c# - String.Replace() will not change the source string of the variable -
this question has answer here:
- c# string replace not work [duplicate] 3 answers
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
Post a Comment