As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
string a = "sea";
string b = "SEA"
if (a == b)...
How could I say that the two strings are the same, regardless of character casing ?
Use string.compare:
http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx
if (string.Compare(a, b, true) == 0)
{
...
}
if (0 == String.Compare(a, b, true))...
http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx
use String.Equals() and use the correct StringComparison-Value:
if(a.Equals(b, StringComparison.CurrentCultureIgnoreCase))
{
...//strings are equal
}
#OP: Please follow the guidelines of whathaveyoutried.com and read the docs... ...this way you would bwe able to answer things like that for yourself and you'll end up learn much more about the language and technique... :)
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
In c#, how can I find a specefic character in a string. this "2222+2222" is my string and I want to find the character "+" in it? I want a function that returns a bool if it finds it.
string.Contains("+") returns a bool.
yourString.IndexOf("+") will return 0 or a positive number if the character is found
Since you prefer something that returns bool, you can use Contains instead but notice that Contains does not provide an overload to perform a case-insensitive search. In scenarios where this is important (finding a string without caring for case), it's best to use IndexOf(stringToSearch,StringComparison.InvariantCultureIgnoreCase) to determine whether the string is found or not.
String s = "2222+2222";
if (s.Contains("+")) {
// dosomething...
}
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I would like to know which way is better and faster for the following scenarios.
string dateStart = ((DateTime)dtRow["StartDate"]).ToShortDateString();
or
string dateStart = DateTime.Parse(dtRow["StartDate"].ToString()).ToString("dd/MM/yyyy")
If the type of value stored in the StartDate column of data-table is already DateTime, the first one is faster than the second. Otherwise we can't compare them, because the first one crashes.
Cast is doubtfully better because is only appropriate way if underlying data is type of DateTime or compatible.
Second way converts DateTime to String and then back to DateTime what is pointless.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am having two dropdownlists and in 1st if I select country another is populated with the corresponding states but I want to grey out the second DDL and display a message like select the state in it. How can I achieve this? I am not using AJAX for this.
Why don't you just temporary disable it on server side?
ddl2.Enabled = false;
Or better do like this, on first changed, check the state, if smth is choosen, then enable secondary ddl.
ddl1_OnSelectedIndexChanged(object sender....)
{
if (ddl1.SelectedIndex != 0)
ddl2.Enabled = true;
}
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
When doing DateTimeConverter.ConvertFromString(" ") it gives back a DateTime.MinValue. You can have as many blank spaces as you want and it still works. If you give it an empty string, it will return null, which I would expect.
This behavior is different than all the other TypeConverters that will either return null or throw an exception.
This is also different than the behavior of DateTime.TryParse(" ") which returns false meaning it didn't work.
I would expect the ConvertFrom method to behave the same as the TryParse method where it should fail if there is an empty or whitespace string.
Why does it do this? Is this a bug?
I'm doing some type conversion and this is a situation where I'm getting unexpected/inconsistent behavior. Is there a way to reliably do type conversion that works for all types? Or do I need to put a special clause in for the DateTime case?
if( typeConverter is DateTimeConverter )
{
// Check if the value is a white space string.
}
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
is there any way i can convert below syntax to LINQ equivalent.
select DateName( month , DateAdd( month , month(cour_date) , 0 ) - 1 ),count(*)
from course
where cour_date>CONVERT(varchar, YEAR(GETDATE())) + '-01' + '-01'
and cour_deleted is null and cour_type='Group'
group by month(cour_date)
order by month(cour_date)
You can use something like this:
var query = from c in course
where c.cour_date > DateTime.Parse("2011-01-01")
&& c.cour_deleted == null && c.cour_type.Equals("Group")
orderby c.cour_date
group c by c.cour_date.Month
For each IGrouping<DateTime, course> in the query you have the Count value, and you can also format the DateTime value of cour_date to convert mount in a string.