ASCII Conversions

Hi guys/girls & traditional geeks..

I am doing a protocol conversion and need two functions

1.) ASCII_To_Text(ASCII_Code : String) : String;

 ie I pass 39 and the result is '

2.) Text_To_ASCII(Txt : String) : String;

 ie I pass ' and the result is 39


Can you please help me ?

Thankyou in advance

Stu

Delphi3
StuartB_99Asked:
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.

rwilson032697Commented:
Use the chr() and ord() functions respectively.

Cheers,

Raymond.
0
StuartB_99Author Commented:
Raymond,
Thanks for the result, the Chr() works spot on, however I am having dificulties using the Ord() function.

It will just be me but here goes,

I have an unknown incoming string ie S
I then have to add up the ascii values of each charector of that string. eg

S := 'This is a test string, part 1';

So I need to go through each charactor adding up its value,

I tried

Function ConvTotal(Data : String) : String;
Var
 I : Integer; // position marker
 T : Integer; // Total
Begin
 For I := 1 To Length Data Do
 Begin
  T := T + Ord(Copy(Data,I,1));
 End;
 Result := IntToStr(T);
End;

I seem to be getting errors at the ord() yet if I put in say Ord('E') that works fine. How should I do this ?

Thanks in advance
Stu (Trainee programmer)
0
StuartB_99Author Commented:
Raymond,
Thanks for the result, the Chr() works spot on, however I am having dificulties using the Ord() function.

It will just be me but here goes,

I have an unknown incoming string ie S
I then have to add up the ascii values of each charector of that string. eg

S := 'This is a test string, part 1';

So I need to go through each charactor adding up its value,

I tried

Function ConvTotal(Data : String) : String;
Var
 I : Integer; // position marker
 T : Integer; // Total
Begin
 For I := 1 To Length Data Do
 Begin
  T := T + Ord(Copy(Data,I,1));
 End;
 Result := IntToStr(T);
End;

I seem to be getting errors at the ord() yet if I put in say Ord('E') that works fine. How should I do this ?

Thanks in advance
Stu (Trainee programmer)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

LischkeCommented:
Stu,

the function must look so:

Function ConvTotal(Data : String) : String;
Var
 I : Integer; // position marker
 T : Integer; // Total
Begin
  T := 0;
 For I := 1 To Length(Data) Do
    Inc(T, Ord(Data[I]);
 Result := IntToStr(T);
End;

Ciao, Mike
0
StuartB_99Author Commented:
Raymond,
Thanks for the result, the Chr() works spot on, however I am having dificulties using the Ord() function.

It will just be me but here goes,

I have an unknown incoming string ie S
I then have to add up the ascii values of each charector of that string. eg

S := 'This is a test string, part 1';

So I need to go through each charactor adding up its value,

I tried

Function ConvTotal(Data : String) : String;
Var
 I : Integer; // position marker
 T : Integer; // Total
Begin
 For I := 1 To Length Data Do
 Begin
  T := T + Ord(Copy(Data,I,1));
 End;
 Result := IntToStr(T);
End;

I seem to be getting errors at the ord() yet if I put in say Ord('E') that works fine. How should I do this ?

Thanks in advance
Stu (Trainee programmer)
0
StuartB_99Author Commented:
Mike,
Fantastic, thanks very much,
Propose the answer and the points are yours, Thankyou raymond aswell, I realy appreciate both of your help.

Stu
0
LischkeCommented:
Stu, I cannot propose an answer while another is already proposed. You have first to reject the other one then I can answer this question.

Ciao, Mike
0
StuartB_99Author Commented:
Mike,
Fantastic, thanks very much,
Propose the answer and the points are yours, Thankyou raymond aswell, I realy appreciate both of your help.

Stu
0
LischkeCommented:
Stu, don't use the refresh button of your browser if you still have the answer link active (AnswerQ is in the link) else you'll resend your last comment... :-) There's abutton "reload question" at the top of the page.

Ciao, Mike
0
LischkeCommented:
Aaah, and I missed that you already rejected the answer :-) Well, then here I am...

Ciao, Mike
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
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.