October 31, 2025, 12:23:49 PM

News:

IWBasic runs in Windows 11!


Finding the last to characters of a string

Started by oneplace2u, January 05, 2010, 07:08:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

oneplace2u

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

mrainey

Read in the user guide about the RIGHT$ and VAL functions and I'll bet you can put something together.
Software For Metalworking
http://closetolerancesoftware.com

celphick

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



billhsln

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
When all else fails, get a bigger hammer.

DennisL

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.

billhsln

Sorry, North, East, West and South, I have no problems with.  Left and Right, I get confused.....

Bill
When all else fails, get a bigger hammer.