java - Insert several chars instead of one into string -
i have string expression. example string "a + b". need insert float variables instead of characters. "a" = 2.4494 , "b" = 5.545466. convert variables string , make strings expression , values char arrays.
expr = expressions.get(i)[0]; // string expression (int j = 0; j < valslistarray.length; j++) {//find characters , values //they should have string selection = (string) valslistarray[j].getselecteditem(); //get //chosen character float valuefloat = segmentareas.get(j); //get value string valuestring = "" + valuefloat; char[] charexpr = expr.tochararray(); // char[] valuechar = valuestring.tochararray(); char[] ch = selection.tochararray(); (int jj = 0; jj < charexpr.length; jj++) { if (charexpr[jj] == ch[0]) { charexpr[jj] = valuechar[0]; //here problem } } string s =new string(charexpr); expr = s; but cant understand how insert whole chararray instead 1 character...
for inserting several chars in array @ once, consider using stringbuilder instead. here's how you'd use it:
stringbuilder sb = new stringbuilder("initial string"); sb.append("another string"); sb.append(new char[] {'c', 'h', 'a', 'r', 's'}); sb.append(1.0f); string str = sb.tostring();
Comments
Post a Comment