Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to overcome this problem?  RSS feed

 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to split the string based on some special character and display the splitted values accordingly.
My job is to get the values from the text fileds append it with some special charater and store it in database.
While displaying retrieve data split and display accordingly..

let us assume i have to get data from 10 text fileds
now my String format is
String str=data1^^^data4^^^^^^ ;
Now tell me how do i retrieve data which is comming from the 5th/6th/7th textfiled here it is empty.How to test it dynamically and retrieve accordingly?
when i use split i will get array length as 4....so while retrieving every time i have to check for array length and retrive based on it.
ie. if array length is 4 i can retrieve upto 4 values and make others empty.
but what if there are 100 text fields and if 50 are empty....here comes the problem i cant check for each and every time.

this array length varies based on the data entered..
hope you people will understand my problem?
Tell me the better way of doing it..
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, String.split(...) works like you describe - if there are empty fields after the last filled field, they will be omitted from the result array. You could write a simple helper method to make it easier:

[ August 17, 2007: Message edited by: Jesper Young ]
 
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was gonna say use StringTokenizer, but it also behaves improperly. They must have both been designed by someone who doesn't have a need to parse delimited input lines.
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Red Smith:
I was gonna say use StringTokenizer, but it also behaves improperly. They must have both been designed by someone who doesn't have a need to parse delimited input lines.



Another option is to use the overloaded version of the split() method that doesn't delete trailing zero-length matches.

Henry
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!