Link to home
Start Free TrialLog in
Avatar of Morgans43
Morgans43

asked on

TryIntToStr and partial strings...

I need to find out if a string contains a number... and return the numeric part in one field and the string parts in (two) other fields.

The string may be along the lines of...

AAAA123456BBBBB or 123456AAAAAAA or AAAAAA123456.

What is the easiest way to pull out the number?
Avatar of kretzschmar
kretzschmar
Flag of Germany image

function WhatEverName(var InputStr, Part2Str : String) : String;
begin
  Part2Str := '';
  result := '';
  for i := 1 to length(InputStr) do
    if inputstr[i] in ['0'..'9'] then
      result := result + inputstr[i]
  inputStr := copy(InputStr,1,length(result));
  Part2Str := copy(InputStr,Length(result),MaxLongInt);
end;

//usage sample
  edit3.Text := WhatEverName(Edit1.text,edit2.text);

whereas
edit3 holds the numberstring
edit1 holds then after call the charstr-part before, if there any
edit2 holds then after call the charstr-part after, if there any

just from scratch
not tested

meikl ;-)
 
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Morgans43
Morgans43

ASKER

That helps... thanks