String splitting and string splitting

Source: Internet
Author: User

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 );}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.