• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Upgrade a String

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

My intention is to Update a String A with a String B.
These strings have a few lines(with "\n") and I want to keep the whole String A and just add the differences from String B
For example:



Has anyone an idea how to do this?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would start by breaking the two strings into arrays. In your example there would be 5 entries in each array. Then I would write some code which went through the two arrays and did the updating which you require. And finally I would convert the updated array back to a string.
 
Ken Masters
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

thank you, maybe that work for me.
The only way I know to write it as an array would be the substring function.
But is there an easier way to do it?

Edit:
Found it!
String[] lines = A.split(System.getProperty("line.separator"));


Thanks, I think I ll make it somehow now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic