Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Split strings with delimiter of ||(double pipe)

Posted on 2009-04-13
3
Medium Priority
?
3,696 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

721 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