Board index » delphi » How to find a substring of text entered into an edit box

How to find a substring of text entered into an edit box

I need to check the text entered into an edit box to see if it starts
with 'ST'. How do I do this as the substring function doesn't work
here.  Also I need to check a character field to see if certain letters
are present somewhere in the string, they could be anywhere within the
string.  How do I do that?  For example, when an item is added to an
order, if a job cost is required then I need to find one of T0, T1, T2,
T3, or 2LB within the string that is the description field of the
product table.  When I find one of these strings in the description then
I know which product type to add the job cost to.  Thanks.
 

Re:How to find a substring of text entered into an edit box


Quote
Rhea Urusky wrote:
> I need to check the text entered into an edit box to see if it starts
> with 'ST'. How do I do this as the substring function doesn't work
> here.

if Copy(Edit1.Text,1,2) = 'ST' then
  ...

Quote
> Also I need to check a character field to see if certain letters
> are present somewhere in the string, they could be anywhere within the
> string.  How do I do that?  For example, when an item is added to an
> order, if a job cost is required then I need to find one of T0, T1, T2,
> T3, or 2LB within the string that is the description field of the
> product table.  When I find one of these strings in the description then
> I know which product type to add the job cost to.  Thanks.

if Pos('T0', ProductTableDescription.AsString) > 0 then
  ...

HTH,

Mike Rodriguez

Re:How to find a substring of text entered into an edit box


To check the first two letters:

if Copy(MyStringValue, 1, 2) = 'ST' then...

To see if a letter exists in a string

if Pos('A', MyStringValue) > 0 then ...

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Other Threads