I'm trying to find the position of the first value that is not a numeric value within a string.
pTxtNumber is passed in and could be 10-15672 for example. So I want to return position 3 because this is the first non numeric character. Then I want to chop of the string up to and including this character so that I am left with 15672.
This code i initially did checks for where the numeric value begins but now i want to do the opposit.
FOR i := 1 TO STRLEN(pTxtNumber) DO BEGIN
IF Pos = 0 THEN
IF FORMAT(pTxtNumber) IN THEN
Pos := i;
END;
Any help would be greatly appreciated.
Cheers
Mike
0
Comments
IF FORMAT(pTxtNumber) IN THEN
put
IF NOT (FORMAT(pTxtNumber) IN ) THEN
I think it could work ...
IF FORMAT(pTxtNumber) NOT IN THEN
and this did not work either.
I suppose i could enter into a substring 'abcdefg-!"£$%^&*' etc and then check in my string to see if it contains any of the characters in the substring but i thought there might be a more efficient way of saying find the first non-numeric character.
Any ideas?
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
<edit>so that still doesn't give you the position of the first non numeric character..... let me think about that</edit>
RIS Plus, LLC
TargetString - Text30
IFoundIt - boolean
MyPos - Integer That should find the first non-numeric character in SourceString. So then you wrap it in a function and use return value.
RIS Plus, LLC
RIS Plus, LLC
AsciiNo is integer
mystr is text
Message returns 48 which is ASCII No. for 0 (zero)
That's all folks... 8)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
RIS Plus, LLC
FOR i := 1 TO STRLEN(pTxtNumber) DO BEGIN
IF FORMAT(pTxtNumber) IN = FALSE THEN
Pos := i;
END;
IntNumber := 0;
IF Pos <> 0 THEN BEGIN
Alpha := DELSTR(pTxtNumber, 1, Pos);
EVALUATE(IntNumber, Alpha);
END;
EXIT(IntNumber);
Thanks for the help!!!
Mike
RIS Plus, LLC
I just wanted to take the part of the string after the non-numeric character which in this case is '-'. So i wanted to return 98765.
mystr := '10-98765';
FOR i := 1 TO STRLEN(mystr) DO BEGIN
IF NOT (mystr IN [48..57]) THEN BEGIN // ascii for 0 thru 9
newstr := COPYSTR(mystr,i+1);
i := STRLEN(mystr); // drops out of for statement
END;
END;
MESSAGE('%1',newstr)
RIS Plus, LLC
RIS Plus, LLC