Raised This Month: $ Target: $400
 0% 

Remove special chars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 07-03-2014 , 11:36   Remove special chars
Reply With Quote #1

Hi, how to remove special chars from string?
If I have this string "[@string()]", how to get just "string"?
FromTheFuture is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 07-03-2014 , 11:42   Re: Remove special chars
Reply With Quote #2

you can create a new string, then with a loop process each character and look if it's right
I don't know about pawn but in other languages, string[i] is the ascii value of the character so you can probably do something like if(x<string[i]<y) where x is the ascii for a and y is capital Z
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-03-2014 , 12:22   Re: Remove special chars
Reply With Quote #3

you can use isalpha() for that too:
PHP Code:
new szString[] = "[Hello]"
new szNewString[sizeof szString]

for(new 
iposcharsmax(szString); i++)
{
    if(
isalpha(szString[i]))
    {
        
szNewString[pos++] = szString[i]
    }

mottzi is offline
Send a message via MSN to mottzi
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-03-2014 , 12:32   Re: Remove special chars
Reply With Quote #4

Can't you just use 'replace_all()' and replace your symbols? If they are more than 1 symbol, just put them in const and loop trough them, replacing all with nothing (""). Wouldn't this work?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-03-2014 , 12:36   Re: Remove special chars
Reply With Quote #5

It would. But he want's to remove all special chars, so you could as well just use something like above. I guess replace_all() doesn't do much more than looping through a string, so it's basicly the same I'd say.
mottzi is offline
Send a message via MSN to mottzi
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 07-03-2014 , 13:32   Re: Remove special chars
Reply With Quote #6

I do this, but may be regex will be better?
PHP Code:
    new iSize sizeof(szToRemove) - 1iCount;
    while(
iSize != iCount)
    {
        
replace_all(szName31szToRemove[iCount], "")
        
iCount++
    } 
FromTheFuture is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-03-2014 , 14:00   Re: Remove special chars
Reply With Quote #7

Using replace_all() will not be very efficient having to loop through all non-letter characters. Regex may or may not be what you want. If you simply want to remove non-letter characters, it is best to do as aron9forever said.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode