Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your requirements, I see two options:</p> <p>(1) Remove the initial prefix character, if present.</p> <p>(2) Use a full regular expression to separate the string.</p> <p>Both are illustrated in this code:</p> <pre><code>using System; using System.Linq; using System.Text.RegularExpressions; class APP { static void Main() { string s = "~Peter~Lois~Chris~Meg~Stewie"; // #1 - Trim+Split Console.WriteLine ("[#1 - Trim+Split]"); string[] result = s.TrimStart('~').Split('~'); foreach (string t in result) { Console.WriteLine("'"+t+"'"); } // #2 - Regex Console.WriteLine ("[#2 - Regex]"); Regex RE = new Regex("~([^~]*)"); MatchCollection theMatches = RE.Matches(s); foreach (Match match in theMatches) { Console.WriteLine("'"+match.Groups[1].Value+"'"); } // #3 - Regex with LINQ [ modified from @ccook's code ] Console.WriteLine ("[#3 - Regex with LINQ]"); Regex.Matches(s, "~([^~]*)") .OfType&lt;Match&gt;() .ToList() .ForEach(m =&gt; Console.WriteLine("'"+m.Groups[1].Value+"'")) ; }} </code></pre> <p>The regular expression in #2 matches the delimiter character followed by a match group containing zero or more non-delimiter characters. The resultant matches are the delimited strings (including any empty strings). For each match, "match.Value" is the entire string including leading delimiter and "match.Groups<a href="http://oreilly.com/catalog/9780596528126/index.html" rel="nofollow noreferrer">1</a>.Value" is the first match group containing the delimiter free string.</p> <p>For completeness, the third encoding (#3) is included showing the same regular expression method in #2, but in a LINQ coding style.</p> <p>If you are struggling with regular expressions, I highly recommend <a href="http://oreilly.com/catalog/9780596528126/index.html" rel="nofollow noreferrer">Mastering Regular Expressions, Third Edition by Jeffrey E. F. Friedl</a>. It is, by far, the best aid to understanding regular expressions and later serves as an excellent reference or refresher as needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload