String splitting and string splitting
Static void Main (string [] args) {// use case of repeated delimiter and demonstration // Use Case |, | is the same as the delimiter, 2 when it is replaced with null | case string content = "1234567890"; string replaceOptions = "1 | a | 2 | 3 | 4 | c "; console. writeLine (replaceContent (content, replaceOptions); Console. readKey ();}
/*** Applicable to 1 | a | 2 | 3 | c mode, compatible with multiple |||**/public static string replaceContent (string content, string filterWord) {ArrayList filterWhiteSpace = new ArrayList (); spliteMuliSymbol (filterWord, ref filterWhiteSpace); for (int I = 0; I <filterWhiteSpace. count; I ++) {string [] replaceArr = filterWhiteSpace [I]. toString (). split ('|'); content = Regex. replace (content, replaceArr [0], replaceArr [1]);} return content ;}
Public static void spliteMuliSymbol (string filterWord, ref ArrayList filterWhiteSpace) {// you can determine whether to replace it with null. if (filterWord. contains ("|") {int whiteSpaceIndex = filterWord. indexOf ("|"); ArrayList arrHalf = new ArrayList (); string firstHalf = filterWord. substring (0, whiteSpaceIndex + 1); string latterHalf = filterWord. substring (whiteSpaceIndex + 3); arrHalf. add (firstHalf); arrHalf. add (latterHalf); for (int I = 0; I <arrHalf. count; I ++) {spliteMuliSymbol (arrHalf [I]. toString (), ref filterWhiteSpace) ;}} else {string [] filterWordArray = Regex. split (filterWord, @ "\ |"); foreach (string temp in filterWordArray) {filterWhiteSpace. add (temp );}}}