• Post Reply Bookmark Topic Watch Topic
  • New Topic

substring Method  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need get the phone of an string like this one for example:



Im using this:



Any idea?

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Im using this:


My question to you would be "WHY are you using that?"

In other words, what are you trying to do? You shouldn't be writing any code until you can explain - in English or some other natural language - what needs to be done in such a way that a child could understand what needs to be done.

And example is great...but it doesn't define the problem or make a spec.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string like this:



in which 333444555 is a phone number (which is a secuence of numbers) I need get the phone number 333444555.

Also I could find a sequence like: .

In this case I need to get the province. I want to build a table, with the important data from a string.

The string can also be like this :

The I should get the phone, email, Copyright, etc

I suppose I should use a substring(), for retrieving every field. But how could I do it in the smartest way? My intention is crawling web sites and get this kind of basic data from them

Regards
Isaac


 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still find this to be rather vague. there appear to be three distinct formats of the Strings you want to parse. So, step one would be to identify which of the three a given string is.

I'm guessing that for the first format - phone number followed by something - you want to get everything from the beginning of the string up to the first non-digit.

The second format is tricky. It's not hard to find the literal "Providence:" in a string. But how do you determine what the providence is? I, as a human, would guess that "Madrid" is what you want..but only because that is a familiar word to me. How do you determine where to stop pulling?

And the third format is even worse.

But I would suggest that - assuming you can determine which of the three formats it is, you consider writing a separate method to process each.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!