Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help in parsing the Stringbuffer  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some data in form of a StringBuffer named as transactions as shown :

Data :




I am parsing this StringBuffer as shown



Now my requirement is that i want to create a String Object for every 120 data of it

Means

String individualTransactions = transactions.subString(0,120);

Please help me in writing the logic inside the for loop .

Thanks in advance .
 
Rob Spoor
Sheriff
Posts: 21047
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) create a String[] that can hold all your Strings. You can calculate its size easily: Math.ceil(transactions.length() / 120.0) (in normal words: the length divided by 120, rounded up).

2) Loop through the StringBuffer in increments of 120:

3) In the loop use StringBuffer.substring(start, end). I'm sure you'll be able to figure out what end should be. Take care if transactions.length() is not a multiple of 120.

3) Store each result of the above call as the next element of the array.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob Prime , for your time ,, I will try and let you know .

Thanks Once again .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!