Solved

Split string at a certain length and put into an array

Posted on 2004-10-17
1
214 Views
Last Modified: 2010-03-31
Hey

I am working on a news ticker and I present text from a mySQL-database. As it is now I have put in "\n" in my table cells and using StringTokenizer and .split to separate the lines into an array. What I want to do now is to be able to remove the "\n"'s in my database tablecells and  to read in the string as a whole. After that I want to use the .split function to cut the string at a certain letter number (length) so at every, let's say, 20th character I want it to split and put those 20 chars as a string into an array.

This is my code as it is now. (working)

           String lines[] = text.split("\\u005cn"); // \u005c is the hex code for the backslash (92 decimal) Splitting up the text and entering the parts into an array

Is it possible to do what I am requesting?
0
Comment
Question by:mindweaver
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 12335257
to split every number of characters you'd use substring() instead of split()
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
array6 challenfge 6 63
Updating Java 9 87
allStar challenge 1 41
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now