Removing Quotes and escaped quotes from string value [duplicate] - c#

This question already has answers here:
C# String.Replace double quotes and Literals
(4 answers)
Closed 1 year ago.
I'm having a really embarrasing moment, as this feels like it's super simple but I just cannot seem to figure out what the best solution is, (or one at all for that matter).
I have a string like so:"\"123456\""
I want 123456
In C#, what is the quickest and easiest way of getting just the value from this? I've looked into using the Regex class and tried the .Unescape() method but I seem to have no success. Please help.

#CharlieFace's answer was the answer that worked for me.
string.Trim('\ "')
Thank you!

Related

Convert from %20 to normal character (replace) [duplicate]

This question already has answers here:
decode percent-encoded string c# .net
(4 answers)
Closed 7 years ago.
I've searched for this and cannot find any hint anywhere.
Basically there is a program that formats their file name like this
hello%20world%28hello%20world%29
which is supposed to mean hello world(hello world)
now im wondering is there any way that I could read every file name and anything that uses "%ascii" would be converted to normal text (e.g above).
Thanks in advance guys. I'm not that experienced in code and I'm hoping that someone could help me.
Use System.Uri.UnescapeDataString:
Uri.UnescapeDataString("hello%20world%28hello%20world%29");
Prints:
hello world(hello world)

First character of string to upper ASP.Net [duplicate]

This question already has answers here:
Is there a native Proper Case string function in C#? [duplicate]
(5 answers)
Closed 9 years ago.
I'm attempting to return a username in ASP.net but would prefer to convert the first character to upper, for example if a username is 'test' I would want to return 'Test'.
Code to get username:
<h3>Welcome Home<strong><%: User.Identity.Name %></strong>.
Not 100% sure on how to implement this and I'm pretty sure it will just end up being something simple but any help would be appreciated.
Thanks
FIXED
h3>Welcome Home <strong><%: User.Identity.Name.ToUpper().Substring(0,1) + User.Identity.Name.ToLower().Substring(1) %></strong>.
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(User.Identity.Name);
You can achive that with the following example
string input;
char.ToUpper(input[0]) + input.Substring(1);
char.ToUpper(User.Identity.Name[0]) + User.Identity.Name.Substring(1)
You don't need any code for that, just use plain CSS:
<h3>Welcome Home<strong style="text-transform: capitalize;"><%: User.Identity.Name %></strong></h3>
Working in all browsers as far as I could see.
Live test case.

Why string.format? [duplicate]

This question already has answers here:
String output: format or concat in C#?
(32 answers)
Why use String.Format? [duplicate]
(7 answers)
Closed 9 years ago.
Why shouldn't we simply use
string s=product.Name+" has been saved";
instead of:
string s=string.Format("{0} has been saved", product.Name);
One naive reason would be that it helps to prevent exactly the string formatting issue that you've presented in your original (unedited) question i.e.
string s=product.Name+"has been saved";
requires an extra space. The format method aids readability.
You could do that, no one say that you cannot. But mainly for readability, the second approach is prefered. It's even more obvious as soon as you concat more than 2 strings, it gets really messy, hard to read and mantain.
If you have many strings that you want to add, each + operation create new string.
For adding many strings you can use StringBuilder Class or String.Format

Splitting these string without clobbering split param's? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to split a string while preserving line endings?
How do I split a string by strings and include the delimiters using .NET?
I'm splitting text into sentences. mystring.Split('.','!', '?') returns the sentences without the ./!/? on them. I need to have it return a sentence with the split param on the end? How does that go? Thanks
public static string[] GetSentences(string text)
{
return text.Split('.', '!', '?');
}
I can think of one way to do it, by combining two separate arrays, but I think it looks awful so I thought I'd ask you professionals for a "proper" way :D
Edit - never mind close its a duplicate. I found the other threads, sorry
Right, string.Split() isn't the right tool here.
Either simply loop through it (string.IndexOf())
or use a RegEx: ([^\.!?]+[\.!?])*
I'm not 100% sure about the escaping.

How to convert 26750 string to 26,750 format in c# [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number
Hi Guys,
I have got 26750 in my string variable, something like below:
string str = "26750";
Now before showing on page, I want it to be converted into "26,750" format using c#. This value can increase as well as decrease also according to the result, so my format should work in both the cases.
Please suggest!
EDIT:
As I have written I have got string type value in my variable, I am trying with below code, but it is not working for me.
spnMiles.InnerHtml = String.Format("{0:n}", Miles);
It is not changing to the number format.
Please suggest!
This question should answers yours:
.NET String.Format() to add commas in thousands place for a number

Categories