Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
string odp = "2,1";
bool abs = odp[1].Equals(",");
When I do Console.Writeline(odp[i]) it shows "," symbol so why does it equal to false?
I tried using == instead but it doesn't work either. Thanks in advance
A Char is encapsulated in single quotation marks ',' in C# (a String uses double quotation marks ",").
Try the below instead:
string odp = "2,1";
bool abs = odp[1].Equals(','); // true
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am using IndexOf to find a character in text. My text include some special characters:
This is my code:
string text = "123<g>ٕ</g>";
int iPosEnd = text.IndexOf(">");
Result:
iPosEnd =10
Why IndexOf did not find character at Position 5?
string.IndexOf(string) does culture-sensitive search. This means it may combine characters when comparing chars. You'll find more info about string comparison in these documentation page:
Compare strings in .NET
Best practices for comparing strings in .NET
String comparisons are harder than it seems
If you want this method to return 5, you can use the char overload or use StringComparison.Ordinal
string text = "123<g>ٕ</g>";
int iPosEnd1 = text.IndexOf(">"); // 10
int iPosEnd2 = text.IndexOf('>'); // 5
int iPosEnd3 = text.IndexOf(">", StringComparison.Ordinal); // 5
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have an encoded query string and have decoded it using the function HttpUtility.UrlDecode(urlEncodedQueryString). It decodes fine and I get the result as:
pagesize=5&morekey=morekey&last_updated=2018-11-30 10:06:09.203&queryfilter=filter
How can I get the value of the last_updated decoded query string (i.e 2018-11-30 10:06:09.203) so that I can parse it to a DateTime and use it for my further implementation?
I tried with this code but it only returns null.
string decodedQueryString = HttpUtility.UrlDecode(urlEncodedQueryString);
var parameters = HttpUtility.ParseQueryString(decodedQueryString);
lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated="]);
I want the lastUpdatedDateUtc values as 2018-11-30 10:06:09.203
Change
lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated="]);
to
lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated"]);
The = isn't supposed to be in the parameter name
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
public string ReplaceTest(int i)
{
string rep = this.textBox3.Text;
string reped = rep.Replace("sir, this.textBox3.Text");
}
Like this? this is what i want to do but another error comes up not all code paths return a value
string.Replace() takes two arguments:
the string to replace
the string to use instead
If you want to remove "sir", it means to replace it with an empty string:
string reped = rep.Replace("sir", string.Empty);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I want to write
Label "BuildingData" does not exist.
I know how to write using String.format and stringbuilder. I want to write this using String.Concat.
When I write code
String.Concat("Label ","\"","BuildingData","\"", "does not exist.")
The output is
Label \"BuildingData\" does not exist.
Add a space before does and you'll get the correct output. The quotes are a red herring - you're looking in the debugger.
using System;
public class Test
{
public static void Main()
{
var concat = String.Concat("Label ","\"","BuildingData","\"", " does not exist.");
Console.WriteLine(concat);
}
}
Here's the output.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
This is a sting like this:
string a = "C:\folder1\folder2\folder3";
I want to separate string a with '\', so write like this:
List<string> result = a.Split('\\').ToList();
But, result only contains ONE member:
{C: older1 older2 older3}
I want to have 4 members in result:
{C:,folder1,folder2,folder3}
So, how shold I do it?
The problem is that your sample string does not contain backslashes.
This string contains three:
string a = "C:\\folder1\\folder2\\folder3";
or this:
string a = #"C:\folder1\folder2\folder3"; // google: verbatim string literal
\f is an escape sequence for formfeed.
Define your string as
string a = #"C:\folder1\folder2\folder3";
so it does not takes backslash as special char.