2

I have this string

"abc,\u000Bdefgh,\u000Bjh,\u000Bkl"

And i need to split the string in c#, every time ,\u000B appears should be a new word.

I tried this:

string[] newString = myString.Split(",\u000B");

but it didnt work, how can i do this?

5
  • 1
    That's only one delimiter that's two characters long. How does it not work? Commented Sep 8, 2011 at 9:02
  • @BoltClock - Probably since there is no overload of Split that takes just a single string as a parameter. Commented Sep 8, 2011 at 9:06
  • 2
    I know, I was prompting the OP to say more than just "it didnt work". Commented Sep 8, 2011 at 9:09
  • @BoltClock - Agreed. From the question is seems that it didn't split the string as he wanted, not that it did not compile at all. Commented Sep 8, 2011 at 9:10
  • thanks, it didnt compile it. there is no overload of Split that takes just a single string as a parameter. Commented Sep 8, 2011 at 9:16

4 Answers 4

9

Change your split command to this:

string[] newString = ip.Split(new[]{",\u000B"}, StringSplitOptions.RemoveEmptyEntries);

Or use, StringSplitOptions.None if you want to preserve empty entries while splitting.

Sign up to request clarification or add additional context in comments.

Comments

3
string[] newString = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.None); 

Works on my machine

Comments

2
        string myString = "abc,\u000Bdefgh,\u000Bjh,\u000Bkl";

        string[] a = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.RemoveEmptyEntries);

1 Comment

:) actually I was faster for a 1 minute, but never mind. The answer you accepted looks more explained
0

You could use the short character escape notation: ",\v" instead.

Short   UTF-16  Description
--------------------------------------------------------------------
\'      \u0027  allow to enter a ' in a character literal, e.g. '\''
\"      \u0022  allow to enter a " in a string literal, e.g. "this is the double quote (\") character"
\\      \u005c  allow to enter a \ character in a character or string literal, e.g. '\\' or "this is the backslash (\\) character"
\0      \u0000  allow to enter the character with code 0
\a      \u0007  alarm (usually the HW beep)
\b      \u0008  back-space
\f      \u000c  form-feed (next page)
\n      \u000a  line-feed (next line)
\r      \u000d  carriage-return (move to the beginning of the line)
\t      \u0009  (horizontal-) tab
\v      \u000b  vertical-tab

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.