Remove quotes from the start and end of a string [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have the string
"{ "type" : "Stage_FF_Hot_Alerts__c"}"
I want to it be
{ "type" : "Stage_FF_Hot_Alerts__c"}
i.e. I want to remove quotes from start and end. How can I achieve this?

You could use Trim:
var a = "\"{ \"type\" : \"Stage_FF_Hot_Alerts__c\"}\"";
var b = a.Trim('"');
Console.WriteLine(a);
Console.WriteLine(b);
It will remove all leading and trailing quotation marks.
Try it online

You can also use:
var quotedString = "\"hello\"";
var unQuotedString = quotedString.TrimStart('"').TrimEnd('"');

Related

How i can get the first match in regex and import this match in a string? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For example using a regex expression del(.*?)del get delcatdel
and save the result in string or in text
word1word2delcatdelword3word4deldogdelword5
in my text (or string) i need obtain delcatdel
USING c sharp
please anybody help me
var regex = new Regex("del(.*?)del");
var match = regex.Match("word1word2delcatdelword3word4deldogdelword5");
string matched = match.Value;

Exclude match in Regular Expression c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I would like to exclude a specific string when it is contained in an expression:
Example:
myurl.htm = exclude
myurl = include
I tried this one : ([a-z0-9]+)(?!.htm)
But looks like it doesn't work.
Try the following:
([a-z0-9]+)(?!^\.htm)
You had two errors in your expression:
You have to escape the dot . with a backslash because it means "matches any character (except newline)" unescaped.
You have to add a ^ to prevent cutting of the last character.
You can test your expression on this website: https://regex101.com/

how to remove particumar letter combination from a string in c#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a string like below
he/a0h/a0dv/a0jks
I would like to be string become as below.
hehdvjks
Need to remove the "/a0" from the string.
The String.Replace method is what you're looking for, just do a;
String myString = "he/a0h/a0dv/a0jks"
myString = myString.Replace("/a0", "")
It'll return a modified 'myString' with all occurrences of the old value ("/a0") replaced with a new value (blank in this case).
The MSDN reference for String.Replace can be found at:
http://msdn.microsoft.com/en-us/library/fk49wtc1%28v=vs.110%29.aspx
var result = "he/a0h/a0dv/a0jks".Replace("/a0", string.Empty);

Simple solution for #"\b \b" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying read one string from TextBox and use in my script.
Suppose this TextBox name is: txt3.
I want read this value and use in below lines:
string s = Regex.Replace(str,
#"\btxt3.Text\b",
txt4.Text,
RegexOptions.IgnoreCase);
How I can write this #"\btxt3.Text\b" ?
I want write that as :
string str==#"\btxt3.Text\b";
You want something like:
String.Format(#"\b{0}\b", txt3.Text)
Try this
string s = Regex.Replace(str, string.Format(#"\b{0}\b",txt3.Text), txt4.Text, RegexOptions.IgnoreCase);
If you want to combine value of txt3 with other strings, one way to do it is write
"\\b" + txt3.Text + "\\b"
instead of
#"\btxt3.Text\b"

How can I get the contents of a string before a particular character? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to get the previous chars from a certain char in a string.
For example: myString = "26+", so I want to get 26 without +. How can I do this?
Use Substring and IndexOf.
string str = "26+";
string requiredString = str.Substring(0, str.IndexOf('+'));
strings are immutable in C# and you have to assign the results to string itself or some other string.
The function String.Substring will do what you need.
yourString.Substring(0, keepCharactersBeforeHere);

Categories