Solved

Split strings with delimiter of ||(double pipe)

Posted on 2009-04-13
3
3,006 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks , that works!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
Viewers will learn the different options available in the Backstage view in Excel 2013.

762 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

10 Experts available now in Live!

Get 1:1 Help Now