IonicWind Software

IWBasic => General Questions => Topic started by: oneplace2u on January 05, 2010, 07:08:38 PM

Title: Finding the last to characters of a string
Post by: oneplace2u on January 05, 2010, 07:08:38 PM
Finding the last two characters of the string below:

XM-160/42 Two Toned Leather Western Belt with Conchos - Size 42

Some of the strings I have are longer and shorter that the one above.

This is what I would like to do with it:
1- I would like to find the last two charaters in the string.
2- I would like to change these two characters to a number.
and then
3. If the last two characters are greater that 42
    then file1 = 4.00
    else
   file1 = 0.00
Title: Re: Finding the last to characters of a string
Post by: mrainey on January 05, 2010, 08:39:25 PM
Read in the user guide about the RIGHT$ and VAL functions and I'll bet you can put something together.
Title: Re: Finding the last to characters of a string
Post by: celphick on January 05, 2010, 08:46:56 PM
QuoteThis is what I would like to do with it:
1- I would like to find the last two characters in the string.

string x
x = "XM-160/42 Two Toned Leather Western Belt with Conchos - Size 42"
x = right$(x,2)


Quote2- I would like to change these two characters to a number.

int n
n = val(x)


Quoteand then
3. If the last two characters are greater that 42
    then file1 = 4.00
    else
   file1 = 0.00

if n > 42
     file1 = 4.00
else
         file1 = 0.00
endif


Title: Re: Finding the last to characters of a string
Post by: billhsln on January 05, 2010, 09:28:08 PM
n = val(x) will not work.  val() expects the string variable passed to it to be numeric, which "XM" is not.  I am guessing that you will have some conversion between XM and a number?

And for the last 2 characters,   

x = left$(x,2)
if x > "42" then file1 = 4.00 else file1 = 0.00

Bill
Title: Re: Finding the last to characters of a string
Post by: DennisL on January 05, 2010, 10:35:40 PM
hi oneplace2u,

unless i'm mistaken, or billhsln lives in a country that reads left to right, then celphick's code should be what you need - i tested with latest ebasic and it works as expected.

cheers, DennisL.
Title: Re: Finding the last to characters of a string
Post by: billhsln on January 05, 2010, 11:03:00 PM
Sorry, North, East, West and South, I have no problems with.  Left and Right, I get confused.....

Bill