Home > Net >  C # string replacement problem, ask for advice!
C # string replacement problem, ask for advice!

Time:10-13

There is a string, containing $STR="this is a test string $... $other characters other characters $... $other characters other characters $... Other characters $... "
$... $content inside is not the same, at the same time to have such an array, a string [] strArray="string 1, 2, 3" string, the number of array elements and the STR string of $... $expression of number is the same, now want to use array strArray inside the string in order to replace the expression in the STR, how to implement this in c # code, ask for advice, I just contact with c #, the regular expression of symbols containing $don't know if you do, seek advice,

CodePudding user response:

Your question is essentially take $.. Between $string with regular is a kind of method is to use the indexof method to get after it is good to replace the
https://www.cnblogs.com/jolins/p/9714238.html found a pick up between two character string method can try
Or you can write their own a according to the logic

CodePudding user response:

A string, and you have to do regular expression

CodePudding user response:

 
Regex reg=new Regex (@ \ $[^ $] + \ "$");
String [] strArray={s1, s2, s3 "};
Int index=0;
Var result=reg. Replace (" this is a test string $... $other characters other characters $... $other characters other characters $... Other characters $... ", x=& gt; StrArray [index++]);
  •  Tags:  
  • C #
  • Related