• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help for simple project  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, basically the title said what I want to say. The project is about sorting a word or string with hastag, mention, and website from a Twitter's status. The rule is the string should be started at # (for hashtag, but no white space), @ (mention, but no white space), or http: (website, with no white space). For example, #homework. I need your help @name. Send me the solution on htttp://www.facebook.com/
Out put should be looked like this
Hashtag: homework
Mention: name
Website: htttp://www.facebook.com/
I tried to use split, but it didn't work at all. I need your help. Thank you
 
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code you have so far and tell us where you're stuck. We will try to guide you to a solution but we won't be doing your assignment for you.
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nhut Khuu wrote:For example, #homework. I need your help @name. Send me the solution on htttp://www.facebook.com/

First thing you need to do is be very clear on your requirements. "#homework." would include the '#' and all non-white-space characters, including the period. Seeing as how that is not the output you are expecting, what are the valid characters that you will allow?
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A robust solution would allow for a list of zero or more hashtags, another list for zero or more mentions, and another for zero or more websites. I'm going to guess here that your requirements are simpler and don't require lists, but again, that is a requirement to be nailed down.
 
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:. . . and welcome to the Ranch

Thank you!!!
 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Nhut Khuu wrote:For example, #homework. I need your help @name. Send me the solution on htttp://www.facebook.com/

First thing you need to do is be very clear on your requirements. "#homework." would include the '#' and all non-white-space characters, including the period. Seeing as how that is not the output you are expecting, what are the valid characters that you will allow?

Well, it's not necessary including the period. Because you can write a hashtag in the middle of the sentence. For example, "I need to do #homework tonight."
But thank you for replying.
 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:A robust solution would allow for a list of zero or more hashtags, another list for zero or more mentions, and another for zero or more websites. I'm going to guess here that your requirements are simpler and don't require lists, but again, that is a requirement to be nailed down.

I'm not sure that I understood what you meant. But I'm pretty sure that I don't have to do the list things.
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line

is exactly the same as

And seeing as how your input doesn't have the pattern "@ " anywhere in it you get nothing.

Regarding requirements: don't confuse examples with requirements. Your requirement states that "The rule is the string should be started at # (for hashtag, but no white space)". This contradicts the example where you don't want to include the period. So the requirement needs to be  flushed out to say something like: "starting after '#' and including all letters and numbers that immediately follow".

Another input example: "I'm going to do my #homework and study for the #exam". In this example you have no mentions and no websites but you do have two hashtags.
 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:This line

is exactly the same as

And seeing as how your input doesn't have the pattern "@ " anywhere in it you get nothing.

Regarding requirements: don't confuse examples with requirements. Your requirement states that "The rule is the string should be started at # (for hashtag, but no white space)". This contradicts the example where you don't want to include the period. So the requirement needs to be  flushed out to say something like: "starting after '#' and including all letters and numbers that immediately follow".

Another input example: "I'm going to do my #homework and study for the #exam". In this example you have no mentions and no websites but you do have two hashtags.


Now I have access to my project, I can specify everything in this problem with the picture below. I'm sorry
Project.png
[Thumbnail for Project.png]
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That info helped.

So, you won't be able to use split() because '#' gives you a starting point but it is not used as a delimiter for the end point.

You can use String.indexOf( "#" ) to find out where the pattern begins.
You can use String.indexOf( " ", begin ) to find the space that follows the "#".
You can use String.substring(begin,end) to extract the piece of the text you want.
 
Sheriff
Posts: 4294
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OP, please UseCodeTags when you post code.  I enabled you to edit your post so you can fix it.  Thanks.
 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:OP, please UseCodeTags when you post code.  I enabled you to edit your post so you can fix it.  Thanks.

Sorry, but I'm new here. How can I edit my post?
 
Ranch Hand
Posts: 39
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If each line might have multiple hashtags to evaluate you might want to use the java.string.utils library and use ordinalIndexOf because you can use it to find multiple instances of your search criteria in a single string.

 
Nhut Khuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:That info helped.

So, you won't be able to use split() because '#' gives you a starting point but it is not used as a delimiter for the end point.

You can use String.indexOf( "#" ) to find out where the pattern begins.
You can use String.indexOf( " ", begin ) to find the space that follows the "#".
You can use String.substring(begin,end) to extract the piece of the text you want.

Thank you very much. I now can do it now.
 
Ranch Foreman
Posts: 920
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nhut Khuu wrote:How can I edit my post?

Using this page you can try out editing posts
https://coderanch.com/wiki/659903/Sand-Box

The subject of editing ones own posts has been discussed fairly recently as shown here:
https://coderanch.com/t/683892/Request-removing-Editing-restrictions
However it looks like Knute may have done some magic for you for that one post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!