I want to build a comma separated list so that I can split on the comma later to get an array of the values. However, the values may have comma's in them. In fact, they may have any normal keyboard character in them (they are supplied from a user). What is a good strategy for determining a character you are sure will not collide with the values?
In case this matters in a language dependent way, I am building the "some character" separated list in C# and sending it to a browser to be split in javascript.
To split a string with specific character as delimiter in Java, call split() method on the string object, and pass the specific character as argument to the split() method. The method returns a String Array with the splits as elements in the array.
Use the Split method when the substrings you want are separated by a known delimiting character (or characters). Regular expressions are useful when the string conforms to a fixed pattern. Use the IndexOf and Substring methods in conjunction when you don't want to extract all of the substrings in a string.
Number of Ways to Split a String - LeetCode. Given a binary string s , you can split s into 3 non-empty strings s1 , s2 , and s3 where s1 + s2 + s3 = s . Return the number of ways s can be split such that the number of ones is the same in s1 , s2 , and s3 . Since the answer may be too large, return it modulo 109 + 7 .
Use the JavaScript String split() to divide a string into an array of substrings by a separator. Use the second parameter ( limit ) to return a limited number of splits.
You could split it by a null character, and terminate your list with a double null character.
If JavaScript is consuming the list, why not send it in the form of a JavaScript array? It already has an established and reliable method for representing a list and escaping characters.
["Value 1", "Value 2", "Escaped \"Quotes\"", "Escaped \\ Backslash"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With