Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Check Each Character of a String?

Reply
Thread Tools

Check Each Character of a String?

 
 
MSUTech
Guest
Posts: n/a
 
      07-11-2005
Hello,

What is the best way to check each character within a string?

For doing something like encryption, where you check character 1 and replace
it with a different character.. then check character 2 and replace it with a
different character.... etc.... until completing the string?

thanks....
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      07-11-2005
=?Utf-8?B?TVNVVGVjaA==?= wrote on 11 jul 2005 in
microsoft.public.inetserver.asp.general:

> What is the best way to check each character within a string?
>
> For doing something like encryption, where you check character 1 and
> replace it with a different character.. then check character 2 and
> replace it with a different character.... etc.... until completing the
> string?
>


vbscript?

myoutput=""

for i=1 to len(mystring)
myoutput = myoutput & checkReplace(mid(mystring,i,1))
next

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-11-2005
MSUTech wrote:
> Hello,
>
> What is the best way to check each character within a string?
>
> For doing something like encryption, where you check character 1 and
> replace it with a different character.. then check character 2 and
> replace it with a different character.... etc.... until completing
> the string?
>
> thanks....


The best way is to use the replace() function.

Get the vbscript documentation here: http://tinyurl.com/7rk6


Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      07-11-2005
Bob Barrows [MVP] wrote on 12 jul 2005 in
microsoft.public.inetserver.asp.general:

> The best way is to use the replace() function.
>


You cannot specify the position with replace()

say the first A needs to become a C
the second A a D


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-11-2005
Evertjan. wrote:
> Bob Barrows [MVP] wrote on 12 jul 2005 in
> microsoft.public.inetserver.asp.general:
>
>> The best way is to use the replace() function.
>>

>
> You cannot specify the position with replace()
>
> say the first A needs to become a C
> the second A a D


Oh, is that what you think he meant? i wish people would learn how to ask
questions ....


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
MSUTech
Guest
Posts: n/a
 
      07-12-2005
My question is how do I look at each character within a string.... for
example...

there is a string "people"

what would be the best way to look at each character....

"p" .... and do some evaluation on the p ... THEN
"e" ... and do some evaluation on the e .... THEN
"o" .... and do some evaluation on the o .... etc....

of course... the string could be ANYTHING.... so, I am just trying to
determine the best way to do a character by character evaluation...

thanks....

"Bob Barrows [MVP]" wrote:

> Evertjan. wrote:
> > Bob Barrows [MVP] wrote on 12 jul 2005 in
> > microsoft.public.inetserver.asp.general:
> >
> >> The best way is to use the replace() function.
> >>

> >
> > You cannot specify the position with replace()
> >
> > say the first A needs to become a C
> > the second A a D

>
> Oh, is that what you think he meant? i wish people would learn how to ask
> questions ....
>
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
>

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-12-2005
Looping through a string could not be simpler:

dim s, i, curchar
s="people"
for i = 1 to len(s)
curchar=mid(s,i,1)
'evaluate the character
select case curchar
case "p"
'do something
case "e"
'do something else
case "o"
'do something else
end select
next

My point is: depending on what you really want to do, looping through the
string may not be the best approach. For example, say you want to replace
all "p" with "u", and all "e" with "z". I think the best way would be to
use Replace:

<%
dim s
s="people"
s=replace(replace(s,"p","u"),"e","z")
response.write s
%>

If you need to do something different, then a loop may be needed. I can't
say for sure without knowing what you really want to do.

Bob Barrows

MSUTech wrote:
> My question is how do I look at each character within a string.... for
> example...
>
> there is a string "people"
>
> what would be the best way to look at each character....
>
> "p" .... and do some evaluation on the p ... THEN
> "e" ... and do some evaluation on the e .... THEN
> "o" .... and do some evaluation on the o .... etc....
>
> of course... the string could be ANYTHING.... so, I am just trying to
> determine the best way to do a character by character evaluation...
>
> thanks....
>


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
MSUTech
Guest
Posts: n/a
 
      07-12-2005
Thanks.... actually, I think you are correct..... REPLACE may be the best
thing to do.. because I will ALWAYS replace a certain character with another
certain character...

so, Thanks!

"Bob Barrows [MVP]" wrote:

> Looping through a string could not be simpler:
>
> dim s, i, curchar
> s="people"
> for i = 1 to len(s)
> curchar=mid(s,i,1)
> 'evaluate the character
> select case curchar
> case "p"
> 'do something
> case "e"
> 'do something else
> case "o"
> 'do something else
> end select
> next
>
> My point is: depending on what you really want to do, looping through the
> string may not be the best approach. For example, say you want to replace
> all "p" with "u", and all "e" with "z". I think the best way would be to
> use Replace:
>
> <%
> dim s
> s="people"
> s=replace(replace(s,"p","u"),"e","z")
> response.write s
> %>
>
> If you need to do something different, then a loop may be needed. I can't
> say for sure without knowing what you really want to do.
>
> Bob Barrows
>
> MSUTech wrote:
> > My question is how do I look at each character within a string.... for
> > example...
> >
> > there is a string "people"
> >
> > what would be the best way to look at each character....
> >
> > "p" .... and do some evaluation on the p ... THEN
> > "e" ... and do some evaluation on the e .... THEN
> > "o" .... and do some evaluation on the o .... etc....
> >
> > of course... the string could be ANYTHING.... so, I am just trying to
> > determine the best way to do a character by character evaluation...
> >
> > thanks....
> >

>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>

 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      07-12-2005
=?Utf-8?B?TVNVVGVjaA==?= wrote on 12 jul 2005 in
microsoft.public.inetserver.asp.general:

> I will ALWAYS replace a certain character
> with another certain character...


In that case, this old and famous rot13 function could be interesting:

Function ROT13(myInput)
Dim txt
txt = ""
Dim character
Dim Position
Const coding =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghij klmnopqrstuvwxyzabcdefghi
jklm"

For i = 1 To Len(myInput)
character = Mid(myInput, i, 1)
position = InStr(coding, character)
If position > 0 Then character = Mid(coding, position + 13, 1)
txt = txt & character
Next
ROT13 = txt
End Function

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      07-12-2005
MSUTech wrote:
> Thanks.... actually, I think you are correct..... REPLACE
> may be the best thing to do.. because I will ALWAYS replace
> a certain character with another certain character...


If I may ask, why are you bothering to implement a simple substitution
cypher?



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform a 2D color image into 2 images of (R1,G1,B) at each pixelof image 1 and (R2,G2,B) at each pixel of image2 for STEREO visualization 88888 Dihedral C++ 10 12-23-2011 02:28 PM
check and convert lower character to upper character alessio211734@yahoo.it C++ 3 11-18-2007 11:28 AM
Array#each - getting each element and the index Pat Maddox Ruby 6 01-20-2006 04:04 PM
how do i? Full scan of each control in each grid row cell John Blair ASP .Net 1 08-03-2005 11:02 AM
xsl:for-each for each 3 elements problem Tjerk Wolterink XML 3 11-03-2004 05:22 PM



Advertisments