Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most reliable split character

Tags:

string

Update

If you were forced to use a single char on a split method, which char would be the most reliable?

Definition of reliable: a split character that is not part of the individual sub strings being split.

like image 422
JL. Avatar asked Dec 10 '09 09:12

JL.


People also ask

How to split a string to an array?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How many ways can you split a string into 3 parts?

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 .

How many ways can you separate a string?

In javascript, we can split a string in 3 ways. One is an old way in which string. split() method is used and later on, ES6 has provided 2 more ways to split a string. In the first way spread operator is used and in the second way array.

How to split string by space in js?

To split a string by multiple spaces, call the split() method, passing it a regular expression, e.g. str. trim(). split(/\s+/) . The regular expression will split the string on one or more spaces and return an array containing the substrings.


2 Answers

We currently use

public const char Separator = ((char)007); 

I think this is the beep sound, if i am not mistaken.

like image 155
Adriaan Stander Avatar answered Sep 19 '22 19:09

Adriaan Stander


Aside from 0x0, which may not be available (because of null-terminated strings, for example), the ASCII control characters between 0x1 and 0x1f are good candidates. The ASCII characters 0x1c-0x1f are even designed for such a thing and have the names File Separator, Group Separator, Record Separator, Unit Separator. However, they are forbidden in transport formats such as XML.

In that case, the characters from the unicode private use code points may be used.

One last option would be to use an escaping strategy, so that the separation character can be entered somehow anyway. However, this complicates the task quite a lot and you cannot use String.Split anymore.

like image 40
nd. Avatar answered Sep 19 '22 19:09

nd.