Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How do i change a string value of
http://host/index.php?p=page
to
http://host/index.php?p=
=
That is not possible.
In .NET strings are immutable, which means that you can't change a string.
What you can do is to create a new string value from the original, for example by copying all of the string except the last four characters:
url = url.Substring(0, url.Length - 4);
Add a comment
Not sure, since you aren't being to clear here, but this does what you ask.
string value = @"http://host/index.php?p=page"; value = @"http://host/index.php?p=";
string s=@"http://host/index.php?p=page"; s=@"http://host/index.php?p=";
string s = @"http://host/index.php?p=page"; s = s.Replace("page", "");
Or, more seriously, you probably want:
string s = @"http://host/index.php?p=page"; s = s.Substring(0, s.LastIndexOf('=') + 1);
This is how I understood your question, will remove anything after the last "="
string s = @"http://host/index.php?p=page"; s = s.Remove(s.LastIndexOf("=")+1);
If you want to strip off everything after the first "=" character:
string s = @"http://host/index.php?p=page" s = s.Split('=')[0] + "=";
Here's one more way:
String oldString = "http://host/index.php?p=page"; String newString = oldString.Substring(0, oldString.IndexOf("?p=") + 3);
Also, if you're lookin to "parameterize" the string.
String.Format("http://host/index.php?p={0}", variableName);
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
=sign?