Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Split string at a certain length and put into an array

Posted on 2004-10-17
1
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 92

Accepted Solution

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:
Suggested Courses

604 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