Changing numbers/non-numbers into numbers only

I need to change a sequence of numbers and non-numbers (groups of possibly 4 but not always) which are separated by dashes into another related sequence of only numbers (always length of 45 in groups of 5) but also separated by dashes.

EXAMPLE:

9244-A4AE-43F4-6598
into
92442-42243-24659-85948-20880-55838-24514-765879-23412

One way of doing this by using the first sequence:

Change non-numbers into 2's (9244-2422-4324-6598)
Remove dashes (9244242243246598)
Add random number/s at end to make 45 characters (9244242243246598 + 594820880558382451476587923412)
Insert a dash after every 5 characters (92442-42243-24659-85948-20880-55838-24514-765879-23412)

You may know a better way.  I need the code to do this.  I am using Delphi 6.  Your help would be greatly appreciated.  Thanks.
rincewind666Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mahdi78Commented:
So you want to change letter by number 2?
9244-A4AE-43F4-6598
9244-2422-4324-6598
0
rincewind666Author Commented:
Yes or any other number
0
Mahdi78Commented:
try this function

function GetMyCode(str: string):string;
const number: string = '1234567890';
var I: integer;
    rand: word;
begin
str := StringReplace(str, '-', '', []);
for I := 1 to Length(str) do
if Pos(str[I], Number) = 0 then
   str := StringReplace(str, str[I], '2', []);
for I := 1 to 11 do
str := str + IntToStr(random(999));
for I := 1 to Length(str) do
if I mod 5 = 0 then
if result = '' then result := copy(str, 1, 5)
else result := result + '-' +copy(str, I - 5, 5) ;
end;
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Mahdi78Commented:
This is update

function GetMyCode(str: string):string;
const number: string = '1234567890';
var I: integer;
    rand: word;
begin
str := StringReplace(str, '-', '', [rfReplaceAll]);
for I := 1 to Length(str) do
   if Pos(str[I], Number) = 0 then
   str := StringReplace(str, str[I], '2', [rfReplaceAll]);
for I := 1 to 11 do str := str + IntToStr(random(999));
Form1.Edit1.Text := str;
for I := 1 to Length(str) do
if I mod 5 = 0 then
if result = '' then result := copy(str, 1, 5)
 else result := result + '-' +copy(str, I - 4, 5) ;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rincewind666Author Commented:
Sorry but it doesn't quite work, although I think it's nearly there.  I get a number like
92442-24222-43242-65980-31860-20227-26703-18161-37142
instead of something like
92442-42243-24659-85948-20880-55838-24514-765879-23412
Note the first groups.

Also, sometimes I get something like
92442-24222-43242-65987-17306-16232-94652-46824-27848-11498
which is 10 groups instead of 9.

I appreciate your help with this.
0
Mahdi78Commented:
You found this result with last post (update)?
0
rincewind666Author Commented:
Opps!  Missed that.  I will try again.
0
twinsoftCommented:
Hi, this does exactly what you want:

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShowMessage(FixString('9244-A4AE-43F4-6598'));
end;

function TForm1.FixString(s: String): String;
var
 i: Integer;
begin
 Result := StringReplace(s, '-', '', [rfReplaceAll]);
 for i := 1 to Length(Result) do
  if Result[i] > '9' then
   Result[i] := '2';
 while Length(Result) < 45 do
  Result := Result + IntToStr(Random(9999));
 Result := Copy(Result, 1, 45);
 for i := 1 to Length(Result) + 5 do
  if i mod 6 = 0 then
   Insert('-', Result, i);
end;
0
rincewind666Author Commented:
Excellent!  It works perfectly.  Many thanks for your help Mahdi78.  It is geatly appreciated.
0
rincewind666Author Commented:
Excellent!  It works perfectly.  Many thanks for your help Mahdi78.  It is greatly appreciated.
0
Mahdi78Commented:
You are welcome, i am glad to help you ;)
0
Mahdi78Commented:
Remove the following line
 Form1.Edit1.Text := str;
0
rincewind666Author Commented:
Yes.  I saw that.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.