473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Check Each Character of a String?

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....
Jul 22 '05 #1
9 12500
=?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)

Jul 22 '05 #2
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"
Jul 22 '05 #3
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)

Jul 22 '05 #4
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"
Jul 22 '05 #5
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"

Jul 22 '05 #6
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.
Jul 22 '05 #7
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.

Jul 22 '05 #8
=?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)

Jul 22 '05 #9
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.
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Greg Bryant | last post by:
I'm working on validating US phone numbers. I have a nice expression that Regex Coach likes, but causes PHP to reject everything I send. Are there any glaring differences? I can't figure out...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
7
by: monomaniac21 | last post by:
Hi guys! Can anyone tell me how you can perform validation on a string variable in PHP so that you can check if a specific character is contained within the string. The reason for this is i am...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
7
by: Lad | last post by:
Hello, How can I check that a string does NOT contain NON English characters? Thanks L.
9
by: eggie5 | last post by:
How would I check if a string is a number? e.g: 'asdf2' =false '34' =true 'asf' =false '0' =true
39
by: emre esirik(hacettepe computer science and enginee | last post by:
int n_mines; printf("How many mines do you want in the minefield?"); scanf("%d", &n_mines); while(n_mines>100 || n_mines<0) { printf("Please only enter between 1 and 100"); scanf("%d",...
3
by: alessio211734 | last post by:
How can I check in c++ string if a character is lower or upper? Exist a function in c++ to convert string to upper characters? Thanks in advance.
17
by: wswilson | last post by:
In python, I could write: a = 1 if a in : do something... In c (and many other languages):
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.