I have to create a function that searches for the first occurrence of the character c (an unsigned char) in the string pointed to by the argument str. The terminating null character is considered to be part of the string.
So i did this:
function my_strchr(str, c){
return str.substring(c.length + str.indexOf(c));
}
But it returns a string without c character. For example, input is "abcabc" && b. Expected output is bcabc, but I have cabc. Could anybody help?
make it like this and it should be okay
return str.substring(str.indexOf(c));
it will start from the index of C till the end of str
check
to know more about the substring()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.