Raised This Month: $32 Target: $400
 8% 

Solved Help with string splitting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thEsp
BANNED
Join Date: Aug 2017
Old 03-22-2019 , 15:54   Help with string splitting
Reply With Quote #1

Hello, I want to know how can I split a string which contains " " (space), but outside quotes.
I tried a variety of functions, neither of them worked. I even tried making a stock, but don't know where the problem is.
For instance, this is a full string: "value num1" "value num2". Instead of returning "value" "num1 ..." it would return the correct way, "value num1","v...".

(Used this ->)
PHP Code:
stock string_arg_split(const string[],right[],left[],const delim[])
{
    new 
return_right[128]
    new 
return_left[128]
    new 
bool:in_quote
    
new bool:is_right
    
    
for(new i=0;i<strlen(string);i++)
    {
        if(
equal(string[i],"^"")) // Code below is red, wth?
        {
            if(in_quote)
            {
                in_quote=false
            }else{
                in_quote=true
            }
        }

        if(!in_quote && equal(string[i],delim))
        {
            if(is_right)
            {
                is_right=false
            }else{
                break
            }
        }else{
            if(is_right)
            {
                add(return_right,charsmax(return_right),string[i])
            }else{
                add(return_left,charsmax(return_left),string[i])
            }
        }
    }
    set_string(2,return_right,strlen(right))
    set_string(3,return_left,strlen(left))

Thank you in advance !

Last edited by thEsp; 03-22-2019 at 16:52. Reason: solved
thEsp is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-22-2019 , 16:41   Re: Help with string splitting
Reply With Quote #2

The red code is because you need ^"^", you have only one. Also, did u try parse?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
thEsp
BANNED
Join Date: Aug 2017
Old 03-22-2019 , 16:52   Re: Help with string splitting
Reply With Quote #3

Quote:
Originally Posted by EFFx View Post
The red code is because you need ^"^", you have only one. Also, did u try parse?
Seems with parse() it works, thank you!
thEsp is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-23-2019 , 08:59   Re: Help with string splitting
Reply With Quote #4

Quote:
Originally Posted by EFFx View Post
The red code is because you need ^"^", you have only one.

Not really he is doing it right it's seems he is seeking for an open qoute character and he is doing it wrong he have to specified the 3rd param in equal function and set it to 1 if(equal(string[i],"^"", 1)) or he could simply check if(string[i] == '^"');
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply


Thread Tools
Display Modes

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 00:46.


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