I have written two lines of code below in vb6. The code is :
d = InStr(s, data1, Chr(13), 1) ' Fine 13 keycode(Enter) form a text data.
sSplit2 = Split(g, Chr(32)) ' Split with 13 Keycode(Enter)
But I can't write above code in C#. Please help me out. How can I write the above code in C#.
In C#, Split() is a string class method. The Split() method returns an array of strings generated by splitting of original string separated by the delimiters passed as a parameter in Split() method. The delimiters can be a character or an array of characters or an array of strings.
Using String. NewLine , which gets the newline string defined for the current environment. Another way to split the string is using a Unicode character array. To split the string by line break, the character array should contain the CR and LF characters, i.e., carriage return \r and line feed \n .
To split a String with multiple characters as delimiters in C#, call Split() on the string instance and pass the delimiter characters array as argument to this method. The method returns a String array with the splits.
I believe you are looking for string.Split:
string str = "Test string" + (char)13 + "some other string";
string[] splitted = str.Split((char)13);
Or you can use:
string[] splitted = str.Split('\r');
For the above you will get two strings in your splitted
array.
the equivalnt code for sSplit2 = Split(g, Chr(32))
is
string[] sSplit2 = g.Split('\n');
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