find second character of any string.
#1

For example second character of string[] = "dog" is "o"
Is there function for this?
Reply
#2

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!!!!"3439); //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.
Reply
#3

Код:
new animalname[4] = "dog";
if(strtolower(animalname)[1] == 'o') {
      // code here
}
I think this should do
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)