tags:

views:

25

answers:

2

I want to change userId to ****. I want to count length of a userId and change the string to that many asterisks. I also want to take the account number and replace all characters except the last 4 XXXX.

How do I do these things?

A: 

Your first one - assuming that your userId is only contains characters A-Z

System.Text.RegularExpressions.Regex.Replace("userID", "[A-z]", "*")
Chris Diver
what do I do if I want to replace all character in userId not only alpha it can have unserscores numbers or alpha
change the regular expression `[A-z]` to `\w` which will match A-z 0-9 and _
Chris Diver
There are *other* ways of manipulating strings besides regexes :) `userid = New String("*"c, userid.Length)`
MarkJ
+1  A: 

Assuming accountNumber and userid are strings

Dim userid As String = "1234"
Dim accountNumber As String = "1234-5678-9876"

userid = New String("*"c, userid.Length)

accountNumber = New String("X"c, accountNumber.Length - 4) & 
                                                      Right(accountNumber, 4)

MsgBox(userid + vbCrLf + accountNumber)
Martin Smith
It worked thanks!!!