How to trim to the first character, for example:
var str="12323{123123}{sdfsdfsdf}"; trim result:
var str1="12323"; var str2="{123123}{sdfsdfsdf}"; while before the symbol {value may be of different lengths. Any ideas? thank you in advance!
How to trim to the first character, for example:
var str="12323{123123}{sdfsdfsdf}"; trim result:
var str1="12323"; var str2="{123123}{sdfsdfsdf}"; while before the symbol {value may be of different lengths. Any ideas? thank you in advance!
var str="12323{123123}{sdfsdfsdf}"; var pos = str.indexOf('{'); // 5 var s1 = str.substr(0,pos); // 12323 var s2 = str.substr(pos); // {123123}{sdfsdfsdf} var str="12323{123123}{sdfsdfsdf}"; var strSplit = str.split('{'); var resultStr= str.substr(strSplit[0].length); var str="12323{123123}{sdfsdfsdf}"; var str1 = str.match(/[a-z0-9]+/i)[0]; // выбор всех букв+цифр (не символов) в первую переменную var str2 = str.substring(str.match(/[^a-z0-9]/i).index); // выбор всего, что после первого символа во вторую переменную Another option with split
var str="12323{123123}{sdfsdfsdf}"; var split = str.split(/({)/); var str1 = split.splice(0,1); var str2 = split.join(''); document.write('str: '+str+'<br/>'); document.write('str1: '+str1+'<br/>'); document.write('str2: '+str2+'<br/>'); var str="12323{123123}{sdfsdfsdf}"; res = str.match(/([^{]+)({.*)/) str1 = res[1] str2 = res[2] Source: https://ru.stackoverflow.com/questions/512600/
All Articles
str.indexOf("{");, then cut the string to this index, and after, well, or how you will need it later. - Moonvvell