c# - Is there a built in function for escaping quotes -
my signup page @ http://nettpals.in/pages/signup, because, i'm creating array of user names.
one users has kept name john'orielly, causing array break.
like this:
var array=['joe','jook','john'orielly']; is there way escape these ' single quotes?
code populate array:
public static string stringtokenizr(this list<string> list, npstringtokenizrtype type, string splitter = ",") { string s = null; if (list.count == 0) return null; (int = 0; < list.count; i++) { if (type == npstringtokenizrtype.integerlike) s += list[i] + splitter; else s += "'" + list[i] + "'" + splitter; } return s.removelast();// removes last comma }
you can way, assuming names stored in generic list:
var array=[<%=string.join(", ", arrnames.convertall(name => string.format("'{0}'", name.replace("'", "\\'"))))%>]; saw edit above 1 liner stringtokenizr have.
Comments
Post a Comment