c# - String.Replace() will not change the source string of the variable -


this question has answer here:

i have following code inside c# application:-

 string[] excludechar = { "|", "\\", "\"", "'", "/", "[", " ]", ":", "<", " >", "+", "=", ",", ";", "?", "*", " @" };  var currentgroupname = curitemsitename;  (int = 0; < excludechar.length; i++)        {          if (currentgroupname.contains(excludechar[i]))              currentgroupname.replace(excludechar[i], "");               }  site.rootweb.sitegroups.add(currentgroupname) 

now in abive code currentgroupname variable passing inside .add function have special characters have replaced inside loop. can adivce if can modify code .replace replacing original string of currentgroupname ...

you not assigning "replaced" string currentgroupname

 string[] excludechar = { "|", "\\", "\"", "'", "/", "[", " ]", ":", "<", " >", "+", "=", ",", ";", "?", "*", " @" };  var currentgroupname = curitemsitename;  (int = 0; < excludechar.length; i++)        {          if (currentgroupname.contains(excludechar[i]))              currentgroupname = currentgroupname.replace(excludechar[i], "");               }  site.rootweb.sitegroups.add(currentgroupname) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -