Raised This Month: $51 Target: $400
 12% 

I have a simply question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
uurbyrkdr
Senior Member
Join Date: Apr 2015
Old 12-19-2015 , 21:30   I have a simply question
Reply With Quote #1

Hi.

How can i add make a string, from "test" to ""test"" ?
I'm trying to write ""test"" but got some errors
sorry for noob question, thanks
uurbyrkdr is offline
uurbyrkdr
Senior Member
Join Date: Apr 2015
Old 12-19-2015 , 21:36   Re: I have a simply question
Reply With Quote #2

tried "\"test\"" , failed
uurbyrkdr is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-19-2015 , 21:43   Re: I have a simply question
Reply With Quote #3

Quote:
Originally Posted by uurbyrkdr View Post
tried "\"test\"" , failed
That is the right way to do it \" the \ indicates that the " is part of the string
fakuivan is offline
uurbyrkdr
Senior Member
Join Date: Apr 2015
Old 12-19-2015 , 21:52   Re: I have a simply question
Reply With Quote #4

Quote:
Originally Posted by fakuivan View Post
That is the right way to do it \" the \ indicates that the " is part of the string
oh sorry, it's my fault

I have a 1 more question.

How can i take the a text from test string, skip x letters?

For example, test string: "This is a test"
and i want take after 5. letter, i mean i want "is a test"
How can i do this?
uurbyrkdr is offline
uurbyrkdr
Senior Member
Join Date: Apr 2015
Old 12-19-2015 , 23:26   Re: I have a simply question
Reply With Quote #5

i made something with while loops, copy string. thank you for helps.
uurbyrkdr is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-20-2015 , 00:21   Re: I have a simply question
Reply With Quote #6

Quote:
Originally Posted by uurbyrkdr View Post
oh sorry, it's my fault

I have a 1 more question.

How can i take the a text from test string, skip x letters?

For example, test string: "This is a test"
and i want take after 5. letter, i mean i want "is a test"
How can i do this?
Strings in SP are just arrays of characters that's why you have to do "char somestring[numberofchars]", so it's easy to operate on them. If you want to strip the first 5 characters from a string you can do something like this:

PHP Code:
void RemoveFirstPart(const char[] sourcechar[] slicedstringint sizeofsourceint sizeofslicedint wheretostart)
{
    for (
int i 0; (sizeofsliced) && (sizeofsource); i++)    //we need to make shure that we are not reading an index that doesn't exist
    
{
        
source[(wheretoslice i)] = slicedstring[i]; //    we are basically writting to the new string to an offset from the source
        
        //    source    This is a test
        //    reuslt         is a test
        //    count     01234567891111
        //                   ^    0123
        //                   | start at this position
    
}

It's that simple, just ask if you need help with something else
fakuivan is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-20-2015 , 00:33   Re: I have a simply question
Reply With Quote #7

if str contains "This is a test", str[5] should reference "is a test"
Miu is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-20-2015 , 03:31   Re: I have a simply question
Reply With Quote #8

str[5] will either point to "is a test" or just the character 'i' depending on what you're doing.

For example

str[5] == 'i' would be true

strcopy(szOut, strlen(szOut), str[5]);

will copy "is a test" to szOut

Code:
stock blob(String:szStr[], cChar)
{
    PrintToChatAll("%s | %c", szStr, cChar);
}

public OnClientDisconnect(iClient)
{
    new String:szFrog[] = "This is a frog.";
    blob(szFrog[5], szFrog[5]);
}
Output: is a frog. | i
__________________

Last edited by Chdata; 12-20-2015 at 03:36.
Chdata 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 06:18.


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