Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split string using multiple delimiters and fixed length

Status
Not open for further replies.

dtqui

Programmer
Sep 25, 2000
62
0
0
SG
Hi,

I need to write a program that splits a length of string to max 5 rows of 25 characters each. The problem is I need to delimit using space, dash, carat (stands for carriage return), backslash etc.

For example,
string= "Beddings/Carpets/Curtains/Cushions"
==> string1 = "Beddings/Carpets/"
string2 = "Curtains/Cushions"

string= "High Fidelity & Stereophonic Equipment-Dealers & Service"
==> string1 = "High Fidelity &"
string2 = "Stereophonic"
string3 = "Equipment-Dealers &"
string4 = "Service"

string= "Churches-Church Of Jesus Christ Of^Latter-Day Saints"
==> string1 = "Churches-Church Of"
string2 = "Jesus Christ Of"
string3 = "Latter-Day Saints"

Problem here is I'm not sure of the logic of the search I should use. Any ready-made codes or pointers are appreciated greatly!
 
To split a String use :

Code:
String s = "abc|def|ghi";
String[] sParts = s.split("|");

for (int i = 0; i < sParts.length; i++) {
  System.out.println("String part is : " +sParts[i] +" and its length is " +sParts[i].length());
}

As for working out your columns and String lengths, you'll have to write your algorithm using the split(), and length() methods.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top