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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting String 1

Status
Not open for further replies.

rclarke

Technical User
May 14, 2001
78
GB
Hello everybody


I have a string

< 10.1234> 20.1234
<=1000.1234>=1000.1111
how can I split this up
so that i have four fields

<=
1000.1234
>=
1000.1111

Do I use VAL()?

Please Help

Thanks in advance

Rachel

 
Hi Rachel,

You cannot do a VAL(myString) and get any value unless it is a numeric expression. First you have to make sure that it is a numeric expression and if it is then you can do a VAL of that.

myString = &quot;<=1000.1234>=1000.1111&quot;

nLength = LEN(myString)
STORE 0 TO nStart1, nStart2, nEnd1

** Get the positions...
FOR I = 1 to nLength
cString = SUBSTR(myString,I,1)
IF nStart1 = 0 AND cString $ &quot;1234567890.&quot;
nStart1 = I
ENDIF
IF nStart1 > 0 AND cString $ &quot;1234567890.&quot;
LOOP
ENDIF
IF nStart1 > 0 AND cString $ &quot;1234567890&quot;
nEnd1 = I
LOOP
ENDIF
IF nStart2 = 0 AND cString $ &quot;1234567890.&quot;
nStart2 = I
EXIT
ENDIF
ENDFOR
**
If nSTart1 > 1
String1 = LEFT(myString,nStart1-1)
ELSE
String1 = &quot;&quot;
ENDIF
Number1 = VAL(SUBSTR(myString,nStart1,nStart2-nStart1))
If nStart2 > 0
String2 = SUBSTR(MYsTRING, nEnd1+1, nStart2-nEnd1-1)
Number2 = RIGHT(myString,nLength-nStart2+1)
ELSE
String2 = &quot;&quot;
ENDIF

I have not tested this... but this will give you the idea to approach the solution.
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Thank you very much is a great help

 
How about this?

yourstr = &quot;<=1000.1234>=1000.111&quot;

*in a temp string, translate all the numeric stuff to &quot;*&quot;
* and append a &quot;?&quot; as a stopsign
tempstr = chrtran(yourstr,&quot;0123456789.&quot;, &quot;***********&quot;)
tempstr = tempstr + &quot;?&quot;

* tempstr now = &quot;<=*********>=********?&quot;

* get the first non-number string
i = 1
field1 = &quot;&quot;
do while substr(tempstr,i,1) <> &quot;*&quot;
field1 = field1 + substr(yourstr,i,1)
i = i + 1
enddo

*get the first number string
field2 = &quot;&quot;
do while substr(tempstr,i,1) = &quot;*&quot;
field2 = field2 + substr(yourstr,i,1)
i = i + 1
enddo

*get the second non-number string
field3 = &quot;&quot;
do while substr(tempstr,i,1) <> &quot;*&quot;
field3 = field3 + substr(yourstr,i,1)
i = i + 1
enddo

*get the second number string, &quot;?&quot; will halt process
field4 = &quot;&quot;
do while substr(tempstr,i,1) = &quot;*&quot;
field4 = field4 + substr(yourstr,i,1)
i = i + 1
enddo


Of course, you may need to substitute something else for the &quot;*&quot; if that can possibly appear. Also, allow for plus- and minus-signs, if needed.

Shanachie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top