3

I'm creating a Mobile website using J2me, ASP and WML.

I read from a DB and created a string as the following so I can later call it.

                string id = reader[0].ToString();
                string name = reader[1].ToString();
                Response.Write("#" + name + id);

in J2me I recall it as

stringItem3.setText("Welcome  "+result.substring(result.indexOf("#")+1)
  + "ID " + result.substring(result.indexOf("#")+2));

and the results are not as I wanted I tried to change a lot with the syntax but with no luck.

the results always show as

enter image description here

while what I really want to show is something like

Welcome  (name)  ID : (id)
or
Welcome  Arin  ID : 20111

What is the best way to get the right results?

And can I later save the id value in a string inside J2me to use it later (yes/No)?


I changed the string (solved)

string id = reader[0].ToString();
string name = reader[1].ToString();
Response.Write("*"+ id + "#" + name); 

and when getting the info

stringItem3.setText("Welcome  "+result.substring(result.indexOf("#")+1)
  + "ID " + result.substring(result.indexOf("*")+1,result.indexOf("#")));

result.substring(result.indexOf("*")+1,result.indexOf("#")));

which is mean to get the chars between "*" and the "#"

now the results are fine as below fig.

enter image description here

1 Answer 1

2

The string you're saving looks like #Arin20111, so indexOf("#")+2 is the 2nd character after the #.

So result.substring(result.indexOf("#")+1) is the entire string after the #, which is the name and ID. And result.substring(result.indexOf("#")+1) is the same string except for the A at the beginning.

If you know the name will never contain a #, you might store the string as #Arin#20111. Then the name is everything after the <sup>st</sup>#and before the 2<sup>nd</sup>#, and the ID is everything after the 2<sup>nd</sup>#`.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the hints I posted what I did in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.