Results 1 to 7 of 7
- 02-21-2014, 10:53 PM #1
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Inserting a newline into a string
Problem: I need to insert a newline into a string where a letter follows a non-letter.
Example String: A63B432
I want to insert a newline after A63
I only have the string class available to me.
I'm familiar with regular expressions however I don't know how to use the String class to insert a newline.
I'm guessing the regular expression I'm looking for would be similar to:
[\.0-9_][a-zA-Z]
(for . OR didgit OR underscore followed by an alpha character)
But how to insert a newline between the two?
Any ideas?
Thanks.
- 02-21-2014, 10:59 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Inserting a newline into a string
Check out the different methods of the Pattern and Matcher classes (which are to do with regular expressions) and you may just get an idea yourself.
Matcher (Java Platform SE 7 )"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 02-21-2014, 11:09 PM #3
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Re: Inserting a newline into a string
Thanks, but as I've said in my original posting, I only have access to the String class.
I can't use Matcher or Pattern.
Anybody have ideas on how to do this with only the String class?
- 02-21-2014, 11:20 PM #4
Re: Inserting a newline into a string
The String class has methods for accessing its characters. See the API doc.
How will you determine if a char in the String is a letter or not?If you don't understand my response, don't ignore it, ask a question.
- 02-21-2014, 11:26 PM #5
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Re: Inserting a newline into a string
I was hoping I could use either [\.0-9_] or \W in the regular expression to represent a non letter character.
- 02-21-2014, 11:52 PM #6
Re: Inserting a newline into a string
Is this a regular expression question?
If you don't understand my response, don't ignore it, ask a question.
- 02-22-2014, 12:04 AM #7
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
inserting a character at multiple places in a string
By DannyGroff in forum New To JavaReplies: 2Last Post: 08-21-2013, 06:46 PM -
Need help with Reading string in text file and inserting them into a singly linked
By Googly in forum New To JavaReplies: 6Last Post: 05-12-2012, 05:29 AM -
Problem inserting String into postgresql.
By ciglesias in forum JDBCReplies: 6Last Post: 04-13-2011, 07:09 PM -
newline in a string
By Billaguana in forum New To JavaReplies: 13Last Post: 01-24-2011, 08:06 PM -
Inserting string with slash character into database
By Java Tip in forum Java TipReplies: 0Last Post: 02-07-2008, 09:57 AM
Bookmarks