I am using scala with play framework.I want to make a hash-tag system like twitter. But I am having problems in case of multi hash-tag. Here is my controller code..
def hashTag = Action{ implicit request =>
val body = request.body.asFormUrlEncoded
var textValue=body.get("text").get(0) //get text value from post method
textValue = textValue.trim()
val array = textValue.split(" ") //split from 'space' to get first word
val firstWord = array(0)
if (firstWord.length() > 1) {
val split = firstWord.split("#") //split word from #
if (split.length >= 2) {
val hashTag = split(1) //fetch first hash-tag from textValue variable
val link = "<a href=\"/hashtag/" + hashTag + "\">" + hashTag + "</a>" //create a link to hash-tag page
textValue=textValue.replace(hashTag, link)
//Insert textValue in database
}//end if
}//end if
}//end hashTag
If i give the input like the string given below then i got hyper link on both instances of Scala hash-tag but not on Java hash-tag. I want to replace Java hash-tag with < a href='/hashtag/Java'>Java and store in database.
#scala #java #scala
How can i do it,please help. Thanks in advance.