Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing unwanted characters

Status
Not open for further replies.

Ragol1

Programmer
Oct 25, 2001
315
US
I use this code to display a users name but if there is a space or some type of character it displays all sorts of characters, I just want it to display just what its reading.


for i = 0 to ubound(aOnline)
if aOnline(i) <> &quot;&quot; then
sUserName = aOnline(i)
sUserName = right(sUserName, len(sUserName) - instr(sUserName, &quot;=&quot;))
response.write &quot; &quot; & sUserName & &quot;<br>&quot;
end if
next
 
Im not sure i understand what you are after...

If you want to get rid of a space on either side of the string you can use &quot;Trim&quot;

NewString = Trim(OldString) '# trims both sides of spaces
NewString = LTrim(OldString) '# trims left side of spaces
NewString = RTrim(OldString) '# trims right side of spaces www.vzio.com
ASP WEB DEVELOPMENT



 
This piece of code grabs a username form a cookie and displays it but if the username has a space in it

It Display Nick+Daines instead of Nick Daines

or lets say user has -Nick-. it displays something like %20d6Nick%208 When I just want it to display -Nick-.


Thanks
 
Ah...

use Replace...

MyString = Replace(MyOldString, &quot;+&quot;, &quot; &quot;)
MyOldString= Replace(MyString, &quot;%20&quot;, &quot; &quot;)
MyString = Replace(MyOldString, &quot;d6&quot;, &quot;-&quot;)

www.vzio.com
ASP WEB DEVELOPMENT



 
So where would I put this on the page?

Nick
MyString = Replace(MyOldString, &quot;+&quot;, &quot; &quot;)
MyOldString= Replace(MyString, &quot;%20&quot;, &quot; &quot;)
MyString = Replace(MyOldString, &quot;d6&quot;, &quot;-&quot;)


for i = 0 to ubound(aOnline)
if aOnline(i) <> &quot;&quot; then
sUserName = aOnline(i)
sUserName = right(sUserName, len(sUserName) - instr(sUserName, &quot;=&quot;))
response.write &quot; &quot; & sUserName & &quot;<br>&quot;
end if
next
 
Put the username in a string, then do the replace function on the username before you print it out, then it will put the characters back to normal. www.vzio.com
ASP WEB DEVELOPMENT



 
OK so if I want to ad more replaces
do I just keep repleteing it

MyString = Replace(MyOldString, &quot;+&quot;, &quot; &quot;)
MyOldString= Replace(MyString, &quot;%20&quot;, &quot; &quot;)
MyString = Replace(MyOldString, &quot;d6&quot;, &quot;-&quot;)
MyString = Replace(MyOldString, &quot;-&quot;, &quot;a&quot;)
MyOldString= Replace(MyString, &quot;%22&quot;, &quot;B&quot;)



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top