FWIW, although it seems intuitively correct, with strings you can not AFAIK use >, <, et cetera.
g.
</div>
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Marked as answer by Qi Wu - MSFT on May 09, 2012 10:52 AM
aspmind
Member
7 Points
24 Posts
compare two string ranges to find if the third string is in between
Apr 30, 2012 06:58 AM|LINK
Hi,
I have a data table with ID, stringA, stringB.
I need to find the ID from the datatable based on stringC, which should between stringA and stringB ranges.
Eg: Find the ID of GRAPE?
ID=1; string-A = APPLE TEST; string-B = ORANGE TEST.
ID=2; string-A = ORGANIC TEST; string-B = SWEET POTATO.
In this case, the answer would be 1. Because the string GRAPE lies between APPLE... and ORANG..... .
(ABCDEFG....XYZ)
How can we do this programatically in C# or javascript.
Paul Linton
Star
13581 Points
2571 Posts
Re: compare two string ranges to find if the third string is in between
Apr 30, 2012 07:14 AM|LINK
if (stringC > stringA && stringC < stringB)
then it is between (exclusive)
rakesh.sawan...
Member
168 Points
173 Posts
Re: compare two string ranges to find if the third string is in between
Apr 30, 2012 03:22 PM|LINK
string str =A + B ;
if (str.contains("GRAPE"))
{
//logic to implement
}
Else
{
//logic to implement
}
aspmind
Member
7 Points
24 Posts
Re: compare two string ranges to find if the third string is in between
Apr 30, 2012 11:46 PM|LINK
Error: "Operator '>' cannot be applied to operands of type 'string' and 'string'.
for the string comparison, I believe its not like the number comparison. you will get the above error.
Paul Linton
Star
13581 Points
2571 Posts
Re: compare two string ranges to find if the third string is in between
Apr 30, 2012 11:49 PM|LINK
(hint - you are trying to COMPARE things)
gerrylowry
All-Star
20577 Points
5721 Posts
Re: compare two string ranges to find if the third string is in between
May 01, 2012 05:59 PM|LINK
@ aspmind TIMTOWTDI =. there is more than one way to do it
You need to study this MSDN article:
http://msdn.microsoft.com/en-us/library/cc165449.aspx "How to: Compare Strings (C# Programming Guide)"
FWIW, although it seems intuitively correct, with strings you can not AFAIK use >, <, et cetera.
g.
</div>