Raised This Month: $ Target: $400
 0% 

Remove Characters


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 04-27-2015 , 08:40   Remove Characters
Reply With Quote #1

Hello Guys.
Is there any way to remove all the characters following the other characters?

Example:

pepethugs lalalalalal

After Remove:

pepethugs

Remove the characters "lalalalalal"
pepe_thugs is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-27-2015 , 09:33   Re: Remove Characters
Reply With Quote #2

Is it supposed to strip everything after a space or is it supposed to strip everything behind that specific phrase "pepethugs"?
__________________
Black Rose is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 04-27-2015 , 11:28   Re: Remove Characters
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
Is it supposed to strip everything after a space or is it supposed to strip everything behind that specific phrase "pepethugs"?
Is to strip after one character. I have this:

Pepethugs <1234><A>

And i want to strip all after pepethugs or strip after "<" Including the character "<"
pepe_thugs is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-27-2015 , 12:05   Re: Remove Characters
Reply With Quote #4

To remove everything after "<", including it, you can do:
PHP Code:
new Pos
if((Pos contain(String"<")) != -1)
{
    
String[Pos] = EOS

__________________

Last edited by HamletEagle; 04-27-2015 at 13:00. Reason: How this could happen ? Thanks Bugsy for seeing.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-27-2015 , 12:54   Re: Remove Characters
Reply With Quote #5

PHP Code:
new Pos
if((Pos contain(String"<")) != -1)
{
    
String[Pos] = EOS

You left a redundant contain(String, "<") in the code
__________________

Last edited by Bugsy; 04-27-2015 at 12:56.
Bugsy is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 04-27-2015 , 17:07   Re: Remove Characters
Reply With Quote #6

Thanks HamletEagle.
I will test it tomorow.

#Bugsy
How you suggest?
thanks
pepe_thugs is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-27-2015 , 20:15   Re: Remove Characters
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
To remove everything after "<", including it, you can do:
PHP Code:
new Pos
if((Pos contain(String"<")) != -1)
{
    
String[Pos] = EOS

Because I know the context here, there is major flaw in this code. If the name contains "<", it will get the wrong one.

@PepeThugs, to avoid an XY Problem, you should always provide the context in which your question is based. This will prevent people making unnecessary mistakes while trying to help you. To help provide this context, it's best if you can post the original code and maybe some of the threads that helped develop that code (if you know where it came from).

I think I found all the original threads: My original function, Original discussion with Pepe_Thugs

You will still need to explain what exactly you want changed (basically the PM you sent to me).
__________________

Last edited by fysiks; 04-27-2015 at 20:17.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-27-2015 , 20:47   Re: Remove Characters
Reply With Quote #8

Quote:
Originally Posted by pepe_thugs View Post
#Bugsy
How you suggest?
thanks
I was just pointing out that HamletEagle had a duplicate piece of code that was not needed.

As fysiks is saying, if the users name contains the '<' character, the string will be cut off there.

For example:

Suppose you were given "Bug<sy <lol123>", you would end up with "bug" instead of "bug<sy " with what HamletEagle posted. If you give more details for what you are trying to do, we can give a better method to accomplish it.
__________________
Bugsy is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-27-2015 , 23:03   Re: Remove Characters
Reply With Quote #9

This is how you can replace from '<' to '>'.
I hope this can help you achieve what you want.

PHP Code:
#define MAX_POS 2048

FindCharsInString(const String[], const Char1, const Char2Pos[MAX_POS])
{
  new 
Total 0;

  for (new 
Iter 0Iter strlen(String); Iter++)
  {
    if (
String[Iter] == Char1 || String[Iter] == Char2)
       
Pos[Total++] = Iter;
  }

  
Pos[Total] = 0;

  return 
Total;
}

{
   static 
Pos[MAX_POS], Total 0;

   
// Ensure that between <> there is no other < or >.
   // But you can also find a way out to escape these ones.
   //
   
new String[128] = "Hattrick <Terrorist><Zombie><Alive>";

   
Total FindCharsInString(String'<''>'PosTotal);
   
// You can then replace in String from Pos[0]+1 to Pos[1]-1, from Pos[2]+1 to Pos[3]-1 and so on...

__________________

Last edited by claudiuhks; 04-28-2015 at 04:24.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 04-28-2015 , 08:35   Re: Remove Characters
Reply With Quote #10

#fysiks

You are wrong fysiks.
Because I'm not using your function.
When I asked you for help was because I was still using your function but not I now use it.
I now use another method.


PHP Code:
public ChangeTagA(id) {
    if ( !( 
<= id <= gMaxPlayers ) || !get_pcvar_num(cvar_TeamTag) )
        return;
        
    new 
pname[65]
    new 
newname[70]
    
    
pname g_szName[id]
    
//get_user_name(id, pname, 64)        
    
pname RemoveOldTag(pnamestrlen(pname))
    
//pname = RemoveOldPoints(pname, strlen(pname))
    
    
if(g_loaded[id])
    {
            
formatex(newname69"%L %s <%d>"LANG_PLAYER"TEAM_A"pnameStaticPoints[id])
            
set_user_info(id"name"newname)
    }
}

public 
RemoveOldTag(pname[65], p_len) {
    
    if ( ( 
containi(pname"a.") != -|| containi(pname"b.") != -) )
    {
        new 
newName[64], indicator
        
new pos containi(pname"a.")
        
        if ( 
pos == -)
            
pos containi(pname"b.")
            
        for ( new 
pos+p_len i++ )
            
newName[indicator++] = pname[i]
            
        
trim(newName)
        
formatex(pnamecharsmax(pname), "%s"newName)
        return 
pname
    
}    
    return 
pname

This code is the plugin made by p1mp.
For this code gets in the tag name "a." and "b."
But I'm getting into the name points forward was why we wanted to remove everything that is in front of the name because in the next match the name also contains the points and I wanted to remove them.
I also wanted to remove "<A>" I am put in the name of admins
pepe_thugs 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 01:09.


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