• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

find integer index in string

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is Ramesh. I am parsing line of text from a string. I have to find a index of the word in a line.this word contains a number.

line of text is like as

AARON JOSEPH AUERBACH JUDITH A 25B PLAZA ST W APT 8M BROOKLYN NY

can any one please give me suggestion how do i find it.

Thanks & Regards
Ramesh K
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use indexOf() methods ....

For more information you can google it or check java apis.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramesh kancherla:
Hi,
This is Ramesh. I am parsing line of text from a string. I have to find a index of the word in a line.this word contains a number.

line of text is like as

AARON JOSEPH AUERBACH JUDITH A 25B PLAZA ST W APT 8M BROOKLYN NY

can any one please give me suggestion how do i find it.

Thanks & Regards
Ramesh K



Yes you can use indexOf() method by passing string parameter that you need to find. But for that the search text should be constant means if as per your given line you can pass indexOf("25B"). then in all lines it will find position of 25B
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a beginner's question. Sounds like a job for regular expressions.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I know indexOf method. But I am taking address from list addresses. so 25B will change in another address.

so how can I find index of the word , it contains number.

can any one please give me suggestion

Thanks & Regards
Ramesh K
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by myself:
Sounds like a beginner's question. Sounds like a job for regular expressions.

Like that.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
how do i write regular expression for the word contains number

can any one please give me suggestion

Thanks & Regards
Ramesh k
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob: suggest you move this thread, please.

Ramesh: have you read the tutorial link I posted?
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Campbell Ritchie ,

I understand how do write regular expression starting with numbers or starting with alphabets.
but i have to find word, containing number . the number position is any position in word. is it possible with regular expression.
if yes please tell me

Thanks & Regards
Ramesh K
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, of course you can create a regular expression for letters-numbers. Have you read the tutorial link?
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell Ritchie ,

yes i have read tutorial. I can write sequence of integers and characters.

but how can I find that numbers with characters not sequence

can you please tell me.

Thanks & Regards
Ramesh K
[ September 10, 2008: Message edited by: ramesh kancherla ]
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramesh kancherla:
Hi Campbell Ritchie ,

yes i have read tutorial. I can write sequence of integers and characters.

but how can I find that numbers with characters not sequence

can you please tell me.

Thanks & Regards
Ramesh K

[ September 10, 2008: Message edited by: ramesh kancherla ]



Hey Ramesh,

I will give you a free code that i was doing once long back for extracting int's from a string.



This Should help you solving the problem ! Its just a BaseLine from which you can customize what you want !

This code will get all integers from the String that you supplied.

What ever format that you need to get it is upto your design and customization !




 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ram kumar:


Hey Ramesh,

I will give you a free code that i was doing once long back for extracting int's from a string.



This Should help you solving the problem ! Its just a BaseLine from which you can customize what you want !

This code will get all integers from the String that you supplied.

What ever format that you need to get it is upto your design and customization !







But Using Regular expresion is the best practice ever !



Try them !
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramesh kancherla:
Hi,
This is Ramesh. I am parsing line of text from a string. I have to find a index of the word in a line.this word contains a number.

line of text is like as

AARON JOSEPH AUERBACH JUDITH A 25B PLAZA ST W APT 8M BROOKLYN NY

can any one please give me suggestion how do i find it.

Thanks & Regards
Ramesh K




 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
It is working fine. Thanks for your help.

Thanks & Regards
Ramesh k
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic