how to retrieve part of a string in java?

Posted by mithun1538 on Stack Overflow See other posts from Stack Overflow or by mithun1538
Published on 2010-04-05T17:23:07Z Indexed on 2010/04/05 17:43 UTC
Read the original article Hit count: 386

Filed under:
|
|

Hello everyone,

I am designing a chat applet. In this, a user will append his name to the beginning of the message that he sends to the other user. In the window of other user, I want to retrieve the appended user name from that string. How do I do that? The message sent by the user is as follows :

final_msg = user_name + ": " + user_message

Hence I want to know how to retrieve the user_name string only. Is there a function that can retrieve a substring upto the first ":"? I dont want to use final_msg.split(":"), because there is a possiblity that the user_message contains ":", which will then give me an array of strings.

© Stack Overflow or respective owner

Related posts about string-manipulation

Related posts about string