English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript to get the characters before the specified character/A simple example of the string after

As shown below:

<!doctype html>
<html>
<head>
<meta charset="utf-8>
<title>Untitled Document</title>
</head>
<script type="text/javascript">
/*
 string string;
 str specifies the character;
 split(), used to split a string into an array of strings;
 split(str)[0], read the value at index 0 of the array (the first value), all array indices are default to start from 0;
 */
function getStr(string,str){
  var str_before = string.split(str)[0];
  var str_after = string.split(str)[1];
  alert('Before: '+str_before+' - After: '+str_after);
}
</script>
<body>
<input type="button" onClick="getStr('string','r');" value="Get Value" />
</body>
</html>

That's all the js to get the specified character before brought to you by the editor/This is the complete example of the string after, I hope everyone will support the cheerleading tutorial~

You May Also Like