Solved

Split strings with delimiter of ||(double pipe)

Posted on 2009-04-13
3
3,083 Views
Last Modified: 2012-05-06
Hi,

I have a string
string words = "1||800||200,19,1,0,2||||114";
string[] sArraycolumns = words .Split(delimiter, System.StringSplitOptions.RemoveEmptyEntries);
But split returns only 1,
800,
200,19,1,0,2
and 114.
i also need to get the blank value between 2 and 114 in sArraycolumns .
How do I do this?


0
Comment
Question by:Enid_JP
3 Comments
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 24135152
Use this

StringSplitOptions.None instead of StringSplitOptions.RemoveEmptyEntries
static void Main(string[] args)

{

     string words = "1||800||200,19,1,0,2||||114";

     string [] delimiter = {"||", ","};
 

     string[] sArraycolumns = words.Split(delimiter, StringSplitOptions.None);
 

     foreach (var s in sArraycolumns)

     {

         Console.WriteLine(s);

     }

}

Open in new window

0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 50 total points
ID: 24135173
Try this:
You have to use RegEx and escape any RegEx specific
characters that might be apart of your pattern.

  string[] text = null;
            string test = "1||800||200,19,1,0,2||||114";
            text = System.Text.RegularExpressions.Regex.Split(test,System.Text.RegularExpressions.Regex.Escape("||"));
0
 

Author Closing Comment

by:Enid_JP
ID: 31569780
Thanks , that works!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now