arrays
c# create xml from byte array
XmlDocument doc = new XmlDocument(); string xml = Encoding.UTF8.GetString(buffer); doc.LoadXml(xml); OR XmlDocument doc = new XmlDocument(); MemoryStream ms = new MemoryStream(buffer); doc.Load(ms); This assumes your data has UTF8 encoding which is the usual for XML. Also buffer here is the byte array.
Sort an associative array in awk
Instead of asort, use asorti(source, destination) which sorts the indices into a new array and you won’t have to copy the array. Then you can use the destination array as pointers into the source array. For your example, you would use it like this: n=asorti(chr_count, sorted) for (i=1; i<=n; i++) { print sorted[i] ” : … Read more
how to add spaces between array items javascript
the array.join function takes an optional delimiter parameter which will seperate the elements by the delimiter. A simple example: var showtimes = [“1pm”, “2pm”, “3pm”]; var showtimesAsString = showtimes.join(‘, ‘); // gives “1pm, 2pm, 3pm”
jq & bash: make JSON array from variable
In jq 1.3 and up you can use the –arg VARIABLE VALUE command-line option: jq -n –arg v “$VAR” ‘{“foo”: $v}’ I.e., –arg sets a variable to the given value so you can then use $varname in your jq program, and now you don’t have to use shell variable interpolation into your jq program. EDIT: … Read more
Length of byte[] array
Use bytes.length without the ()
How to save each line of text file as array through powershell
The Get-Content command returns each line from a text file as a separate string, so will give you an array (so long as you don’t use the -Raw parameter; which causes all lines to be combined to a single string). [string[]]$arrayFromFile = Get-Content -Path ‘C:\USER\Documents\Collections\collection.txt’ In his excellent answer, mklement0 gives a lot more detail … Read more
Integer to Integer Array C# [duplicate]
A simple solution using LINQ int[] result = yourInt.ToString().Select(o=> Convert.ToInt32(o) – 48 ).ToArray()
What is the difference between removeLast() and popLast() methods of Array in Swift?
Those two methods are from AnyRandomAccessCollection which Array conforms to. popLast returns nil if the collection is empty. removeLast crashes if the collection is empty. It also has a discardable result.