If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

What would happen if your string was 'joookool'? Would you want 'j3k2l'?
If you want to use multiple strings to search and count, like 'ez' in 'jezezezkezl' giving 'j3k2l', then I'd perhaps:

Replace all the strings (say 'ez') with a single char (say *), [using String.replaceAll?]
Then create a temporary string,
Then create a simpler loop to step through the new string (containg the *s), with an 'IF' saying
'if it's not a *, add it to the new tempstring, but if it is a * then count them until there are no more *s, then add the number to the temp string and move on.'

hi ArchAngel

well the output: L3o2pa is correctly what i want but as i'm a beginner i dunno how to do it.Should i use twise "while" command???And the most importent is how can i do this for every STRING.Lets say i use my keyboard and my code should do the following:

OK. You just have to think about this logically and be able to work out the steps required ON PAPER before you start coding. Something like:

Code:

Keep track of the current character: "current"
Keep track of the number of times the current character has appeared in a row: "counter"
REPEAT
Move to the next character
IF this character is the same as the previous THEN
Increment "counter"
ELSE
IF the "counter" is greater than 0 THEN
display "counter" followed by "current"
ELSE
display "current"
END IF
Update "current" to be the new character
Reset "counter" to zero.
END IF
END REPEAT

I've had a run through this a couple of times and it seems about right...understand it and then have a go at coding it yourself.

:(

hello ArchAngel, this is how i interpret your code:

Code:

index = text.indexOf(oStr); //Keep track of the current character: "current"
while(index>=0) //Keep track of the number of times the current character has appeared in a row: "counter"
{
index = index + oStr.length();//Move to the next character
oCount++;//Increment "counter"
if(oCount>0) //IF the "counter" is greater than 0 THEN
System.out.print(+oCount +oStr); //display "counter" followed by "current"
else
System.out.print( oStr); //display "current"
index = text.indexOf(oStr,index); //Update "current" to be the new character
oCount=0; //Reset "counter" to zero.

the output is: 1o1o1o

a question:how can i track if the charackter is same as the previos,i cant convert string into boolean(that is saying my compiler)...