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.... 9 12531
=?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)
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"
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)
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"
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"
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.
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.
=?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)
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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
|
by: Lad |
last post by:
Hello,
How can I check that a string does NOT contain NON English characters?
Thanks
L.
|
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
|
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",...
|
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.
|
by: wswilson |
last post by:
In python, I could write:
a = 1
if a in :
do something...
In c (and many other languages):
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |