AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remove special chars (https://forums.alliedmods.net/showthread.php?t=243362)

FromTheFuture 07-03-2014 11:36

Remove special chars
 
Hi, how to remove special chars from string?
If I have this string "[@string()]", how to get just "string"?

aron9forever 07-03-2014 11:42

Re: Remove special chars
 
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

mottzi 07-03-2014 12:22

Re: Remove special chars
 
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]
    }



Flick3rR 07-03-2014 12:32

Re: Remove special chars
 
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?

mottzi 07-03-2014 12:36

Re: Remove special chars
 
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.

FromTheFuture 07-03-2014 13:32

Re: Remove special chars
 
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++
    } 


fysiks 07-03-2014 14:00

Re: Remove special chars
 
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.


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

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