Solved

Split strings with delimiter of ||(double pipe)

Posted on 2009-04-13
3
3,149 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

776 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