vbGore Free Online RPG Engine

Revolutionizing Visual Basic ORPG Development
It is currently Sun May 19, 2013 9:47 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Remove characters from a string
PostPosted: Tue Jan 29, 2008 9:33 pm 
Newbie

Joined: Tue Jan 29, 2008 9:28 pm
Posts: 5
Well... basically i want to remove all characters from the variable (declared as a string) strcool that are not numbers, letters or spaces. Basically I want to remove characters like "$$" or "@ |||||", then output it to a textbox or label.
Anyone have any idea how i could do this?
Oh and would it be possible to put this in a timer and have it constantly remove these characters from the string?


Thanks in advance!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 10:49 pm 
Bytewise Operator

Joined: Mon Sep 03, 2007 9:57 am
Posts: 130
Location: San Antonio, TX
replace(stringtosearch,searchforstring,replacewithstring)

so if i do
sRet = replace("Tamnk is an awesome guy","guy","dude")

sRet would = "Tamnk is an awesome dude"

but i guess if you are trying to remove any string characters you do not want to add you could do something like



private function SuperCoolReplacer(thestring as string) as string
dim validstring as string
dim mychar as string
dim x as long

for x = 1 to len(thestring)
mychar = Mid(thestring, x, 1)

if (asc(lcase(mychar)) >= 97 And asc(lcase(mychar)) <= 122) Or asc(mychar) = 32 Then
validstring = validstring + mychar
end if
next x

SuperCoolReplacer = validstring

end function

(97 = lowercase "A" and 122 = lowercase "Z" and 32 = a space. so that would basically take out anything that was not between A-Z and not a space. you'd need to modify it to allow for other characters you want to allow.)

then you just say

dim mystringtoreplace as string
dim mynewstring as string

mystringtoreplace = "!THIS !$#WILL $#B#!E $%A$W$@E%SOME$ M$AN"
mynewstring = SuperCoolReplacer(mystringtoreplace)

and mynewstring should now = "THIS WILL BE AWESOME MAN"

obviously i didn't test this so maybe i have a syntax error or two but it's late =)


**EDIT** sorry just to keep people from getting confused i been mostly using the + lately because work has me doing some ASP and i use + instead of the more common & to join strings together. In VB6 you can use either one.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 11:33 pm 
Newbie

Joined: Tue Jan 29, 2008 9:28 pm
Posts: 5
thank you, i think i understand the code, its late and ill try to get it to work in the morning :) this seems like it should work :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 10:24 pm 
Newbie

Joined: Tue Jan 29, 2008 9:28 pm
Posts: 5
EDIT: THIS WORKS GREAT THANK YOU!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group