| View previous topic :: View next topic |
| Author |
Message |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Sep 05, 2002 3:08 pm Post subject: CHR to ASC |
|
|
How can I get the ASC value of a string...can I get the ASC value of each letter and put it back together in a string? For example, how can I change "FreezingFire" into something like
%%variable = FreezingFire
%%letter1 = @asc(@substr(%%variable,0,0)
and get it to work...I haven't been able to so far... _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1565
|
Posted: Thu Sep 05, 2002 4:00 pm Post subject: |
|
|
Try this little code I threw together, I use a seperator | in between each ascii value so you can later rebuild the word with the asc2chr routine i've also included:
| Code: |
option fieldsep,|
%%theword = "FreezingFire"
gosub GetAscii
%%theword = "72|101|108|108|111|32|87|111|114|108|100"
gosub GetChars
exit
:GetAscii
%%pos = 1
repeat
%%ascword = %%ascword|@asc(@substr(%%theword,%%pos))
%%pos = @succ(%%pos)
until @greater(%%pos,@len(%%theword))
%%ascword = @substr(%%ascword,2,@len(%%ascword))
warn %%ascword
exit
:GetChars
repeat
%%slashpos = @pos(|,%%theword)
if @greater(%%slashpos,0)
%%chrword = %%chrword@chr(@substr(%%theword,1,@pred(%%slashpos)))
%%theword = @strdel(%%theword,1,%%slashpos)
end
until @equal(@pos(|,%%theword),0)
%%chrword = %%chrword@chr(%%theword)
warn %%chrword
exit
|
|
|
| Back to top |
|
 |
Hortalonus Valued Contributor


Joined: 15 Mar 2002 Posts: 344 Location: Western USA
|
Posted: Thu Sep 05, 2002 4:58 pm Post subject: |
|
|
| That's handy... thanks PG! |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Sep 05, 2002 7:23 pm Post subject: |
|
|
Here's a little routine that I use to convert text from an edit box to
ascii values:
| Code: | rem -- Convert text to Ascii
%%TotalLength = @len(@dlgtext(Edit1))
%%CurrentCnt = 1
%%CurrentText = @dlgtext(Edit1)
%%Output =
Repeat
%%Output = %%Output""@asc(@substr(%%CurrentText,%%CurrentCnt,%%CurrentCnt))" "
%%CurrentCnt = @succ(%%CurrentCnt)
Until @greater(%%CurrentCnt,%%TotalLength)
Dialog Set,Edit2,
Dialog Set,Edit2,%%Output |
The values are seperated by a space.
And just for the heck of it, in case you ever need it, here's a routine
to convert to hex values:
| Code: | rem -- Convert text to Hex
%%TotalLength = @len(@dlgtext(Edit1))
%%CurrentCnt = 1
%%CurrentText = @dlgtext(Edit1)
%%Output =
Repeat
%%Output = %%Output""@hex(@asc(@substr(%%CurrentText,%%CurrentCnt,%%CurrentCnt)),2)" "
%%CurrentCnt = @succ(%%CurrentCnt)
Until @greater(%%CurrentCnt,%%TotalLength)
Dialog Set,Edit2,
Dialog Set,Edit2,%%Output |
Again, seperated by spaces.
Us PK's example to convert in other directions, just remember, I
used spaces to seperate the values and not the pipe character.
-Garrett |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Thu Sep 05, 2002 7:25 pm Post subject: |
|
|
With hex the advantage is that you won't need any separator character inbetween each character's
code, as the hex values are of fixed length. |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Sep 05, 2002 7:33 pm Post subject: |
|
|
Ah gees.... That's right... DoH! and I put spaces between the hex values.....
-Garrett |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Sep 05, 2002 9:38 pm Post subject: |
|
|
Thank you...it works great!
 _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|