English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a coding problem that is a lill tricky for me to solve, please suggest a good solution

String s = "Line5: this is line 5Line1: this is line 1 Line4:this is line 4 line3:this is line 3"


Ok I want the lines .. this is line 'x', where x=1,2,3,4 ... n, in a String array( lets suppose).

the order of int with string i.e; Line 1 , Line 2 is not fixed, Line 10 may come at first place and Line 1 could come at 3rd place etc.

My delimiting character is "Line x:" or "line x:", where x = 1,2,3 .. n

Any suggestion.....??

2007-05-23 19:16:02 · 2 answers · asked by ali hammad 1 in Computers & Internet Programming & Design

2 answers

I imagine that counting the number of ':' characters will tell you how many lines you have to process. If not then you must have a limit. If you do not have a limit to the line number or the number of lines then this does indeed become a tricky problem.

So

n=1
Loop until limit
Find 'Line n:'
if find result is -1 then
nothing
else
store index in an array
store length in array. // Length = length of 'Line n:'
Store n in array.
add 1 to n
end-if
end-loop.

// you now have an array or three arrays with all the
// information you need to split the lines.

Sort the array(s) on index.

// Now you can split the string.
// If you want the lines in sequence then sort the array again
// on n.

2007-05-23 20:30:50 · answer #1 · answered by AnalProgrammer 7 · 0 0

in case you elect the string to incorporate in basic terms what's interior the quotations, then: String f = "4+3^2="; in case you elect the cost back with the help of the calculations, then: int answer = 4+ pow(3,2); String f = "+answer+";

2016-10-05 22:58:03 · answer #2 · answered by ? 4 · 0 0

fedest.com, questions and answers