forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


CHR to ASC

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Sep 05, 2002 3:08 pm    Post subject: CHR to ASC Reply with quote

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
View user's profile Send private message Visit poster's website
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1565

PostPosted: Thu Sep 05, 2002 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hortalonus
Valued Contributor
Valued Contributor


Joined: 15 Mar 2002
Posts: 344
Location: Western USA

PostPosted: Thu Sep 05, 2002 4:58 pm    Post subject: Reply with quote

That's handy... thanks PG!
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Sep 05, 2002 7:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Tommy
Admin Team


Joined: 16 Nov 2002
Posts: 746
Location: The Netherlands

PostPosted: Thu Sep 05, 2002 7:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Sep 05, 2002 7:33 pm    Post subject: Reply with quote

Ah gees.... That's right... DoH! and I put spaces between the hex values..... Embarassed

-Garrett
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Sep 05, 2002 9:38 pm    Post subject: Reply with quote

Thank you...it works great! Very Happy

Worship

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group