Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String.IndexOf()
- String.IndexOf()
- public List<string> ParseWords(string s)
- {
- List<string> words = new List<string>();
- int pos = 0;
- while (pos < s.Length)
- {
- // Get word start
- int start = pos;
- // Get word end
- pos = s.IndexOf('|', pos);
- while (pos > 0 && s[pos - 1] == '\')
- {
- pos++;
- pos = s.IndexOf('|', pos);
- }
- // Adjust for pipe not found
- if (pos < 0)
- pos = s.Length;
- // Extract this word
- words.Add(s.Substring(start, pos - start));
- // Skip over pipe
- if (pos < s.Length)
- pos++;
- }
- return words;
- }
- string test = @"This|is|a|pip|ed|test (this is a pip|ed test)";
- string[] parts = Regex.Split(test, @"(?<!(?<!\)*\)|");
- string sPipeSplit = "This|is|a|pip\|ed|test (this is a pip|ed test)";
- string sTempString = sPipeSplit.Replace("\|", "¬"); //replace | with non printable character
- string[] sSplitString = sTempString.Split('|');
- //string sFirstString = sSplitString[0].Replace("¬", "\|"); //If you have fixed number of fields and you are copying to other field use replace while copying to other field.
- /* Or you could use a loop to replace everything at once
- foreach (string si in sSplitString)
- {
- si.Replace("¬", "\|");
- }
- */
- string text = @"This|is|a|pip|ed|test"; //The original text
- string parsed = ""; //Where you will store the parsed string
- bool flag = false;
- foreach (var x in text.Split('|')) {
- bool endsWithArroba = x.EndsWith(@"");
- parsed += flag ? "|" + x + " " : endsWithArroba ? x.Substring(0, x.Length-1) : x + " ";
- flag = endsWithArroba;
- }
- /^(?:((?:[^|\]|(?:\{2})|\|)+)(?:||$))*/
- ^ #The start of a line
- (?:...
- [^|\] #A character other than | or OR
- (?:\{2})* #An even number of characters OR
- \| #A literal followed by a literal |
- ...)+ #Repeat the preceding at least once
- (?:$||) #Either a literal | or the end of a line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement