Page 1 of 1

String Comparison

Posted: Mon Jul 12, 2004 10:10 am
by appcon
I am working on a string comparision issue where I need to bring out a numbers start with a particular char or number.

Here is an example.

I have 123
234
235
237
456


I need to bring out any number that start with 2. So the result should be 234,235,237.

Has anyone come across this scenario. Any suggestions would be appreciated.

Thanks.

Posted: Mon Jul 12, 2004 10:43 am
by chulett
One way would be to simply substring the first character off and check to see if it is a '2'.

Code: Select all

If YourField[1,1] = "2" Then DoSomething Else DoSomethingElse
You could also do something similar in a Constraint:

Code: Select all

YourField[1,1] = "2"
Depends on what you mean by 'bring out'. You may need to add a 'trim' to that if there can be leading spaces involved.

Posted: Mon Jul 12, 2004 10:38 pm
by vmcburney
You can do your own experimentation on functions by writing a dummy routine and using the Test button to test various values. You will find this improves your knowledge of BASIC commands.
Create a routine, put into this routine the line:
Ans = left(234, 1), or
Ans = 234[1, 1] or
Ans = left(Arg1, 1)
Compile it and use the Test button to view the results. If your input field is numeric then you will be testing left(234, 1), if it's string you'll be testing left("234", 1). They both seem to give the same result. Looks like basic is very forgiving when it comes to sending a numeric field into a string function.

Posted: Tue Jul 13, 2004 1:00 pm
by gh_amitava
Hi,

For perfect result, You should use 'Trim' function before using 'Left' function because the argument is a string.. So your syntax should be like Left(Trim(string_var),1)

Regards
Amitava Ghosh