Raised This Month: $ Target: $400
 0% 

Deleting chars from string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Horex
Member
Join Date: Sep 2009
Old 04-24-2010 , 11:32   Deleting chars from string
Reply With Quote #1

How to delete "Horex" " from the beginning
and " from the end of that string: "Horex" "bind "x" "say hello""

I though about coping parts of strings but in sourcemod reference is nothing like that.

strcopy(g_preexec, sizeof(g_preexec), newValue)

doesn't allow me to copy parts of string i want :-/
Horex is offline
wyrda
Member
Join Date: Nov 2009
Old 04-24-2010 , 12:19   Re: Deleting chars from string
Reply With Quote #2

Do you know the size of the string you want to remove?
Please give a better example.
__________________
wyrda is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-24-2010 , 12:35   Re: Deleting chars from string
Reply With Quote #3

To remove the first character of a string, use myString[1] - this tells SM to start reading the string from the first byte, rather than the zeroth. To remove the last character, simply set it to null, and the string terminates one character earlier.

Here's an example from the Signal code:

PHP Code:
new start 0;
new 
lastchar strlen(arguments) - 1;

if (
arguments[lastchar] == '"') {
    
arguments[lastchar] = '\0';
    
start 1;

From that point on, use "arguments[start]" as the string, rather than "arguments".
__________________
Scone is offline
Horex
Member
Join Date: Sep 2009
Old 04-24-2010 , 19:38   Re: Deleting chars from string
Reply With Quote #4

It helped. Thank you.

Here is a plugin I've REmaded thanks to you: http://forums.alliedmods.net/showpos...1&postcount=61

PHP Code:
    if (args 2) {
        
GetCmdArg (1szClientsizeof (szClient));
        
GetCmdArgString(szCommandsizeof (szCommand));
        new 
lastchar strlen(szCommand) - 1
        if (
szCommand[lastchar] == '"') { 
            
szCommand[lastchar] = '\0'
        }
        for(new 
i=0;i<3;i++) {
            
pos FindCharInString(szCommand'"'false)+1;
            
strcopy(szCommandsizeof(szCommand), szCommand[pos]);
            
pos=0;
        }
        if (
szCommand[0] == '"') {
            
strcopy(szCommandsizeof(szCommand), szCommand[1]);
        }
    } 
Horex 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 05:20.


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