0

I have such string:

   string mystr = "[email protected]|Action Required to Activate Membership for ClanTemplates|href="|">|6|6";

How to parse it to array of strings with "|" delimiter?

3 Answers 3

2

You can just use String.Split();

string mystr = "[email protected]|Action Required to Activate Membership for ClanTemplates|href="|">|6|6";
string[] parts = mystr.Split(new char[] { '|' });
Sign up to request clarification or add additional context in comments.

2 Comments

i get: Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Look at my sample, i'm using mystr.Split() directly.
1

Just use the Split method; no need for a regex.

string[] parts = mystr.Split('|');

2 Comments

Sorry Luke, thought I was editing my answer, don't know what happened. Feel free to roll back.
I've followed my answer back through the post, don't know why it didn't go through. Very strange.
0

If you really want to use Regex, you need to remember to escape the | as \| in raw regex, and in C#, "\\|" or @"\|".

string[] parts = Regex.Split (input, @"\|");

For something simple like this, just use string[] parts = input.Split('|'). You shouldn't use regex in this case unless there's something special, like not wanting to split on escaped pipes (like [email protected]|my value has a \| in it|more stuff'). In this example, you would use this:

string[] parts = Regex.Split (input, @"(?<!\\)\|");

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.