• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1459
  • Last Modified:

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?
0
Morgans43
Asked:
Morgans43
  • 2
1 Solution
 
kretzschmarCommented:
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 ;-)
 
0
 
kretzschmarCommented:
sorry one mistake in this line after review

inputStr := copy(InputStr,1,length(result));
 
should be

inputStr := copy(InputStr,1,pos(inputstr,result)-1);
 

maybe i have the pos parameter mixed
->pos(result,inputstr)
and the -1 is not needed

meikl ;-)
0
 
Morgans43Author Commented:
That helps... thanks
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now