String function in JavaScript

xiaoxiao2021-03-06  56

Then give a loop again, the condition is index! = - 1. In each cycle, we add a variable index plus 1, that is, from the first character after the found "a", starts to find until all the characters "a" find it. When there is no character "a", it will return -1 value when it is found in the string variable mysring, and Index is equal to -1, which does not satisfy the cycle condition index! = - 1, so that the loop ends. The output of the ALERT (index) statement is: 1, 5, 13. In this example we just show indexof () search for single characters. If you often use this function, you will find that it can search for any character or string. CHARAT () function This function returns the character in the string in a given location. In essence, it is a special case of the subString () method, but it also has its own use. If you are a C language programmer or a similar language programmer, you can understand the string.charat (index) instead of String [index] when you reference characters. Let's use this function in a form input. There is an email address in the form, of course, this email address is limited to character, number, and a "@" symbol. We can tell a single character in a one-time string to force it. Detailed codes are as follows: