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 saved few directory locations to a Dictionary<string, string>,
e.g.
C:\\WINDOWS\\system32\\abc\\123
But the value that gets stored in the dictionary is C:\WINDOWS\system32\abc\123
So when I later compare a value against one in the dictionary it does a comparison like this:
C:\WINDOWS\system32\abc\123
to this
C:\\WINDOWS\\system32\\abc\\123
How can I retain backslashes when storing values in a Dictionary?
Try this:
Dict.Add(key, #"C:\\WINDOWS\\system32\\abc\\123");
\ is an escape character. Adding # makes your string a string literal instead.
EDIT I've reproduced your issue and this fix will solve it.
Use the # symbol in front of the strings when saving. That should solve it.
Related
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 1 year ago.
Improve this question
For Example I have String like this:
""dear customer{Customer name} your reference number is {referenceNumber}"
I want to get array=["{Customer name}",{referenceNumber}]"
I have to split based on curly bracket inside bracket value is changeable means it can be different for different cases I just need to split and get array of value inside brackets including brackets.
If you think about it, splitting on { and } will produce an array where every odd index is what you want..
.Split('{','}').Where((s,i)=>i%2==1).Select(s=>'{' + s + '}').ToArray();
Split the string, use the LINQ Where function that passes the int index to the predicate, insist that the index be odd (mod2 is 1) and select a new string that puts the brackets back on, ToArray
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 2 years ago.
Improve this question
I want to create a regular expression to check the following string pattern, I tried following these tutorials but it's still confusing. Any help is appreciated.
Type: In Folder
(T or t)ype(spaces or no space):(spaces or no space)(i or I)n(spaces or multiple space)(f or F)older
So following your desired pattern at the end of your question:
(t|T)ype\s*:\s*(i|I)n\s*(f|F)older
The above pattern should match your string. Mind you, \s* is zero to unlimited spaces, which means it would match on the string you provided even if there were no spaces present; if there will always be at least one space present, you can replace them with \s+
Hope this helps!
(T|t)ype\s*:\s*(I|i)n\s*(f|F)older
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/
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 8 years ago.
Improve this question
I don't understand what is wrong i did the same code with the insert and run well
Entity obj = new Entity();
.
.
.
obj.DEPID = decimal.Parse(((TextBox)GridView1.FooterRow.FindControl("txtDEPID")).Text);
myFactory.UpdateObject(obj);
The value that is returned by the
((TextBox)GridView1.FooterRow.FindControl("txtDEPID")).Text
Is not a decimal-like string. It contains some other Special Characters like alphabets etc.
While passing the values, you need to make sure that the values being passed match the values required. Check what is the value of this.
txtDEPID.Text;
Use it in a MessageBox, to check for the value. I'm sure there is some sort of non decimal part in the string. Which is causing the trouble while converting the String to Decimal.
MessageBox.Show(txtDEPID.Text);
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);