Rob Bamforth's Blog
Java, SQL,T-SQL, MySQL, Networking, SQL Server, PHP, COM, DBA, ODBC

Posts Tagged ‘JAVA replace string within a string’

JAVA replace string within a string

October 22, 2008

The following code replaces an instance of a string within a string:
String testString = “This is a text string”
testString = testString.replace(“text string”, “sentance”);
testString will now print “This is a sentance”.
The replace() function is case sensative, and will only carry out the replace if the case matches both strings.