vbscript regex

M

Michael L.

Hi there,

I'm looking for a way to replace each occurence of each character in a
string to different characters.

i.e - the pattern is a=d, b=e, c=f

so that the string "back" would be "edfk"

How can I do that?

Thanks!
 
R

Ray at

What would z become, }? Would Z become ]? Do you want case sensitivity?
Numbers?

Ray at work
 
C

Chris Hohmann

Michael L. said:
Hi there,

I'm looking for a way to replace each occurence of each character in a
string to different characters.

i.e - the pattern is a=d, b=e, c=f

so that the string "back" would be "edfk"

How can I do that?

Thanks!

<script language="VBScript" runat="SERVER">
Function crf(m,p,s)
crf = Chr(Asc(m)+3)
End Function

Dim re
Set re = New RegExp
With re
.Global = True
.Pattern = "[abc]"
Response.Write .Replace("back",GetRef("crf"))
End With
</script>

<script language="JavaScript" runat="SERVER">
Response.Write("back".replace(/[abc]/g,function(m,p,s){return
String.fromCharCode(m.charCodeAt(0)+3);}));
</script>


HTH
-Chris Hohmann
 
M

Michael L.

Chris hi,

Actually I need "a" to become: "%20%40", "b" to become: "%D0%B5", etc.

This is a special converting I need, that has to be case senstive. (I will
fill in the rest of the switching).

Really what I'm after is a way to replace 1 set of strings (in a list) to a
2nd set of strings.

So that "backa" would be something like:

%D0%B5%20%40ck%20%40 (assuming I defined replacements only for a and b)

Can you help?

Thanks!

Chris Hohmann said:
Michael L. said:
Hi there,

I'm looking for a way to replace each occurence of each character in a
string to different characters.

i.e - the pattern is a=d, b=e, c=f

so that the string "back" would be "edfk"

How can I do that?

Thanks!

<script language="VBScript" runat="SERVER">
Function crf(m,p,s)
crf = Chr(Asc(m)+3)
End Function

Dim re
Set re = New RegExp
With re
.Global = True
.Pattern = "[abc]"
Response.Write .Replace("back",GetRef("crf"))
End With
</script>

<script language="JavaScript" runat="SERVER">
Response.Write("back".replace(/[abc]/g,function(m,p,s){return
String.fromCharCode(m.charCodeAt(0)+3);}));
</script>


HTH
-Chris Hohmann
 
C

Chris Hohmann

Michael L. said:
Chris hi,

Actually I need "a" to become: "%20%40", "b" to become: "%D0%B5", etc.

This is a special converting I need, that has to be case senstive. (I will
fill in the rest of the switching).

Really what I'm after is a way to replace 1 set of strings (in a list) to a
2nd set of strings.

So that "backa" would be something like:

%D0%B5%20%40ck%20%40 (assuming I defined replacements only for a and b)

Can you help?

Thanks!

Chris Hohmann said:
Michael L. said:
Hi there,

I'm looking for a way to replace each occurence of each character in a
string to different characters.

i.e - the pattern is a=d, b=e, c=f

so that the string "back" would be "edfk"

How can I do that?

Thanks!

<script language="VBScript" runat="SERVER">
Function crf(m,p,s)
crf = Chr(Asc(m)+3)
End Function

Dim re
Set re = New RegExp
With re
.Global = True
.Pattern = "[abc]"
Response.Write .Replace("back",GetRef("crf"))
End With
</script>

<script language="JavaScript" runat="SERVER">
Response.Write("back".replace(/[abc]/g,function(m,p,s){return
String.fromCharCode(m.charCodeAt(0)+3);}));
</script>


HTH
-Chris Hohmann

Function crf(m,p,s)
Select Case m
Case "a" crf = "%20%40"
Case "b" crf = "%D0%B5"
End Select
End Function

HTH
-Chris Hohmann

P.S. Please do not top post/bottom quote. It makes it difficult for
others who are trying to follow this thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top