Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reversing - substr 1

Status
Not open for further replies.

reinaldo

Programmer
Mar 29, 2001
31
US
subStr([TABLENAME.Field], 6, 1)
the above code will give me the first value on the right of a number with 6 digits, as in
123456 - the value I will get will be the number 6
therefore I am gettin the first digit on the right of a six digit number. Is there a way to get the formula to read from left to right so that if I have 3 different numbers like
123456
12345
1234
I will get the value to be 1, or the first number
 

To get the last Number from the Right use:
//if field contain text (field size > 0) return ""
//else return the char in string[n] (n=size of the string)

iif(smallint(Size([TABLENAME.Field]))>0,substr([TABLENAME.Field],smallint(Size(TABLENAME.Field)),1),"")

To get the first number from the left use :
//if field contain text (field size > 0) return ""
//else return the char at pos string[1]

iif(smallint(Size([TABLENAME.Field]))>0,substr([TABLENAME.Field],1,1),"")


hope this will help..
jb
 
Grr guess i need an other cofee..
//if field contain text return blabla
//else return ""

:) sorry



 
thank you jbpelletier I was able to use your second example (from left) to work perhaps I was not clear in what I want to accomplish

subStr([EXPENSES.Field], 6, 1) (currency field)

the above code will give me the first value on the right of a number with 6 digits, as in 123456 - the value I will get will be the number 6 therefore I am getting the first digit on the right of a six digit number. Is there a way to get the formula to read from left to right so that if I have 3 different numbers like

123456
12345
1234

I will get the value to be the first number from the right or the second number from the right or the third number from the right.
 
I'm not clear what you want, but something like
SUBSTR(NumVar, LEN(NumVar), 1)
will get the last digit of the number

To get, say the 3rd from last digit

SUBSTR(NumVar, LEN(NumVar)-2, 1)

So 123456 will give 4
12345 will give 3
1234 will give 2

Phil
 
thanks PhilUK but it stll does not work

Paradox 9 calculated field

SUBSTR([INVOICE.Amount Paid], LEN([INVOICE.Amount Paid]),1)

your help will be appreciated
 
Q : Is there a way to get the formula to read from left to right.

R: yes .. the substr will do it..

//str_MyString = the string u whant to split
//int_From = from left.. where do i start to read..
//int_NBChar = how many char will i return..

SUBSTR(str_MyString,int_From,int_NbChar)


So if u have 12345 in str_MyString..
//to get the first char from left
//start at pos 1.. return 1 char
SUBSTR(str_MyString,1,1)

//to get the 3 first char from left
//start at pos 1.. return 3 char
SUBSTR(str_MyString,1,3)

//to get 1 digit from right
//from the last char (size of string) return 1 char
SUBSTR(str_MyString,smallint(Size(str_MyString)),1)

//to get 3 digit from right
//from the last char - 2 (size of string-2) return 3 char
SUBSTR(str_MyString,smallint(Size(str_MyString))-2,3)

but if u whant to get something like 54321 from str_mystring i dont think u can do that in a calc field..
i really dont think u can read from right to left.. its always left to right but u can get the X last char of a string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top