find second character of any string. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: find second character of any string. (
/showthread.php?tid=645092)
find second character of any string. -
srvr07 - 19.11.2017
For example second character of string[] = "dog" is "o"
Is there function for this?
Re: find second character of any string. -
Swankeh - 19.11.2017
Quote:
Originally Posted by srvr07
For example second character of string[] = "dog" is "o"
Is there function for this?
|
https://sampwiki.blast.hk/wiki/Strmid
You can use this function, I will explain to you so you can see how it works.
strmid(string, "Extract 'HELLO' without the !!!!: HELLO!!!!", 34, 39); //string contains "HELLO"
Example:
PHP код:
new String[8];//With this variable we will store the letter or letters that you want to extract.
strmid(String, "Extract 'HELLO' without the !!!!: HELLO!!!!", 34, 39); //string contains "HELLO"
//strimd(param1, param2, param3, param4);
//param 1 The string to store the extracted characters in.
//param 2 The string from which to extract characters.
//param 3 The position of the first character or the part where you want to start extracting the text.
//param 4 The position of the last character or the final part where you want to start extracting the text.
printf("%s", String); //We print to screen to check what works.
//Result: HELLO
If you have any questions, I can help you with pleasure.
Re: find second character of any string. -
JaydenJason - 19.11.2017
Код:
new animalname[4] = "dog";
if(strtolower(animalname)[1] == 'o') {
// code here
}
I think this should do
Re: find second character of any string. -
NaS - 19.11.2017
Quote:
Originally Posted by JaydenJason
Код:
new animalname = "dog";
if(strtolower(animalname)[1] == 'o') {
// code here
}
I think this should do
|
No.
It's unneccessary to convert the whole string if only one character needs to be checked.
Furthermore you cannot do it like that, you'd need to use a buffer string and then check Index 1 of that string (which can be completely avoided using the code below).
Код:
if(tolower(string[1]) == 'o')
{
// Stuff..
}
If the case is important, leave away tolower.