Welcome! Log In Create A New Profile

Advanced

Finding an expression in a string

Posted by Milton 
Milton
Finding an expression in a string
March 18, 2009 12:34AM
Hi All,

I think I may have done this in the past but cannot remember how -

I want to search a string from left to right until I encounter the first "space" and then capture the data to the left of the space.

For example if the string is "1~2 something" I want to capture the "1~2" part of the string.

Can anyone help please?

Thanks,

Milton
DerekT
Re: Finding an expression in a string
March 18, 2009 12:44AM
Milton

nPos is string
nPos = Position("1~2 something"," ",FromBeginning) should do the trick.
nPos will return 4

Regards

DerekT
Milton
Re: Finding an expression in a string
March 18, 2009 01:02AM
Hi Derek,

Thanks mate - I will give it a try.

Milton
Milton
Re: Finding an expression in a string
March 18, 2009 02:24AM
Hi Derek,

I used your advice on a file I had created, already imported from an Excel spreadsheet (pps$), to add the data I wanted with the exception that I created the variable nPos as an integer rrather than a string.

HOpen(pps$,"",hOReadWrite)
HReadFirst(pps$,pps$.JobName)
WHILE NOT HOut(pps$)
nPos = Position(pps$.Description1," ",FromBeginning)
pps$.nPos=nPos
pps$.PartDesc=Left(pps$.Description1,(nPos-1))
HWrite(pps$,hCurrentRecNum)
HReadNext(pps$,pps$.JobName)
END

It worked perfectly so thanks a lot.

Milton
Louis Verbraak
Re: Finding an expression in a string
March 18, 2009 08:44AM
Hello Milton,

You can use ExtractString for that:

sSubString=ExtractString(sCompleteString," ",firstRank)

HTH.
Milton
Re: Finding an expression in a string
March 18, 2009 11:22AM
Hi Louis,

Thanks for the information.

Milton
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: