473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

splitting string

hai,

hai i have constant maximum length... Based on that maximum length i have to split one string ..how to do in java...

Example:


String number= "000101051105210100010545";

spilt into 00010/1051105/210100/010545 like this .. this should be constant assigned to one variable




Regards
Asha
Nov 9 '11 #1
1 1731
I would do it as follows: convert the string into a character array and then using a for-loop, insert a "/" at every 4th position (if your counter starts at 0)
Expand|Select|Wrap|Line Numbers
  1.     public static String divideString(String sampleString, int breakPosition){
  2.  
  3.         char[] charString = sampleString.toCharArray();
  4.         String newString = "";
  5.  
  6.         for(int i = 0; i < charString.length; i++){
  7.             if(charString.length % breakPosition == 0)
  8.                 newString+="/";
  9.             newString += charString[i];
  10.         }
  11.         return newString;
  12.     }
  13.  
that should do it for you...
Nov 10 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guadala Harry | last post by:
I have a string that must be split out into a string array. The segment delimiter is like this: {flag:xxx} and the "xxx" part is unknown ahead of time (can be just about any character AND any...
1
by: sadiewms | last post by:
Hello! I have a flat file that I'm trying to get into a relational Access 2003 DB. One of the fields in the flat file has a list of names separated by ";". I'd like to loop through them and...
7
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace,...
4
by: VMI | last post by:
How can I split a string that looks like this: John, Doe, 37282, box 2, 10001, "My description, very important", X, Home If I use String.Split(), it'll split the string that's between the...
3
by: Ramper | last post by:
I need to Write a function that will, given an input string containing many words, split that string into individual words. For each word, the function should output the word, its starting index in...
7
by: Matik | last post by:
Hi to everyone, My problem is, that I'm not so quite sure, which way should I go. The user is inputing by second part application a long string (let's say 128 characters), which are separated...
12
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
13
LucasBishop
by: LucasBishop | last post by:
Hi everyone; i'm working with a program that can't split a strig of characters if i introduce out of the program. It only work's if the string is put it directly in the the soucer code, here it is:...
4
by: John | last post by:
1. Is there an easy function in VB to count for instance the number of A's in a string? 2. Is there an easy funtion in VB to pull all characters out of a string into an array? (I tried the split...
10
by: CSharper | last post by:
I have a html page that I retrived and stored in a string and I want to split it based on <tdelements. I know only way you can split using string.split is using characters. The other option is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.