Is this possible?

H

harry

I want to achieve some sort of parameter substitution, whereby one string is
inserted in to a specifc position within another string - the same as with a
resources file i.e {0}

So if -
st1 = "There is an Error in {0} - stop what you are doing!"
&
str2 = "Project Search"

Is there a simple way of producing -

str3 = "There is an Error in 'Project Search' - stop what you are
doing!"

thanks

harry
 
V

VisionSet

harry said:
I want to achieve some sort of parameter substitution, whereby one string is
inserted in to a specifc position within another string - the same as with a
resources file i.e {0}

So if -
st1 = "There is an Error in {0} - stop what you are doing!"
&
str2 = "Project Search"

Is there a simple way of producing -

str3 = "There is an Error in 'Project Search' - stop what you are
doing!"

You would have to use curly braces wouldn't you!


st1.replaceFirst("\\{0\\}{1}", str2);

I think

see java.util.regex.Pattern docs
 
H

harry

Thanks for the fast response Mike, works just as I wanted! (sorry about the
curly braces, copied the idea from my resources file!)
 
D

Daniel Dyer

You would have to use curly braces wouldn't you!


st1.replaceFirst("\\{0\\}{1}", str2);

I think

see java.util.regex.Pattern docs

java.text.MessageFormat

It especially likes the curly braces.

Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top