replace string

Hi All,

I have one String

str1 = "123 678 8910";

I have another String

str2 = "000 111 0000 0000";

I am looking for the way and if possible sample code to replace value of str2 with str1 based on byte position.

How can I replace value of postion 2-5 from str1 with value of 3-6 from str2.

[331 byte] By [sameer_13va] at [2007-11-27 10:57:19]
# 1

StringBuilder and String.substring are probably a good start.

jverda at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 2

I dont want to use substring, is there any other best approach as this is just a sample my string is huge

sameer_13va at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 3

> I dont want to use substring...

Any particular reason why?

~

yawmarka at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 4

> I dont want to use substring, is there any other best

> approach as this is just a sample my string is huge

As you want to replace sections based on their index position I can't think of any way other than substring()... otherwise you could use replace() and replaceAll(). But they will just replace specific instances wherever they are in the string and not just at specific locations.

c0demonk3ya at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 5

my record is huge and I have to do lot of mapping, so was looking for some like collection or similar if possible to use and replace based on byte position

sameer_13va at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 6

> my record is huge and I have to do lot of mapping, so

> was looking for some like collection or similar if

> possible to use and replace based on byte position

How is that drastically different than using StringBuilder.replace() and String.substring()?

~

yawmarka at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...
# 7

> > my record is huge and I have to do lot of

> mapping, so

> > was looking for some like collection or similar if

> > possible to use and replace based on byte

> position

>

> How is that drastically different than using

> StringBuilder.replace() and String.substring()?

>

> ~

<some mumblings about efficiency here> ?

georgemca at 2007-7-29 12:08:26 > top of Java-index,Java Essentials,Java Programming...