dimanche 3 mai 2015

Using regex to find chars in a string and replace

When returning a string value from an incoming request in my network based app, I have a string like this 'post http://a.com\r\nHost: a.com\r\n'

Issue is that the host is always changing so I need to replace it with my defined host. To accomplish that I tried using regex but am stuck trying to find the 'host:a.com' chars in the string and replacing it with a defined valued.

I tried using this example http://ift.tt/1zohISF changing the pattern compile to :([\\d]+) but it still remains unchanged.

My goal is to replace given chars in a string with a defined value and returning the new string with the defined value. Any pointers?

Aucun commentaire:

Enregistrer un commentaire