[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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
0
StuartB_99
Asked:
StuartB_99
  • 5
  • 4
1 Solution
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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