you can’t use string.Remove inside a static method because Remove is an instance method. So what alternatives do you have besides regex to remove a specific character in a string? What I’m trying to do is remove any backslashes in a long string that I have. so “\” for example is in a string that I am evaluating.
Example:
public static FacebookSession CreateNewSessionFromCookie(HttpCookie facebookAuthCookie)
{
..some logic
String.Remove(facebookAuthCookie["\"access_token"].Length-1, 1);
...rest of the code
I get an immediate error on the Remove method of “Cannot access non-static method Remove in static context”
So above I attempted to remove the last “\” in the cookie value. Ideally I want to remove all instances of “\” in that string but I can’t get this to even test because of that complile error.
Hm, I think you might be thinking of this wrong. You can use String.Remove inside any method you’ve written, static or not, but String.Remove is an instance method of a string. You’d call it like so: