• 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

Replace a substring in a string full of " : , and repeating string

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am getting a string as input like this --

I need to replace \x14\x14\x14\x02 with ABCDEF so that the modified string will be --

I have the string ipAddressAddr with me.Suppose input string variable we are considering as input.So gives me starting index of ipAddressAddr which is 45.To replace \x14\x14\x14\x02 I need index of "," after index 45 then I can do some substring and replace option.

What should be the efficient way

Thanks
Abhra
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

replace \x14\x14\x14\x02 with ABCDEF


Have you tried using the String class's replace method?
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't, I have ipAddressAddr only. Whatever comes in between and the very next   I need to replace with ABCDEF .It can be "\x14\x14\x14\x02" or 123456 or anything.I want to find out the index of very next "," after "\x14\x14\x14\x02".  Or if any other better way to do.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I do not understand what you are trying to do.
You said: replace \x14\x14\x14\x02 with ABCDEF

Now you say there is more to solving the problem than just that simple replace method.
Please explain why that simple replace does not work.  Give some example showing where it fails.
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
value = \x14\x14\x14\x02 is a dynamic value.It can be anything like ABC , A, AB etc(Just example) .I will have to use replace method only. But to know about the string which need to be replace I need to do some substring operation,Like ---



Now indexOf(",") should return the index of ' which comes after \x14\x14\x14\x02.
If you see the whole string "," apearing before \x14\x14\x14\x02 also.

My requirement is to find the the index of "," just after \x14\x14\x14\x02.


Thanks
Abhra
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

value = \x14\x14\x14\x02 is a dynamic value.It can be anything


Ok, so the project is to find some subString that does not follow some rules and must be replaced by some other subString.

My requirement is to find the the index of "," just after ...


Once you find the subString in the a above search, you will be able to find the next "," that follows it
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What should be the code for finding next index of ","
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Got it.There is a inbuild method only.

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic