Solved

Split strings with delimiter of ||(double pipe)

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
This collection of functions covers all the normal rounding methods of just about any numeric value.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

820 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