Parallel Language Reference : Strings - Replace parts of a string with a string




C#
 
string someString = "The one the only the dude";
someString = someString.Replace("the", "and"); 
// The one and only and dude - case sensitive
 
VB.net
 
Dim someString As String = "The one the only the dude"
someString = someString.Replace("the", "and")
// The one and only and dude - case sensitive
 
Delphi
 
SomeString:= 'The one the only the dude';
SomeString:= StringReplace(SomeString, 'the', 'and', [rfReplaceAll]);
// The one and only and dude - ignore case by adding flag to last
// parameter eg. [rfIgnoreCase, rfReplaceAll] or replace only first
// occurrence by omitting rfReplaceAll flag
 
Java
 
String someString = "The one the only the dude";
someString = someString.replace("the", "and");
// The one and only and dude - case sensitive
 
PHP
 
$someString = "The one the only the dude";
$someString = str_replace("the", "and", $someString);
// The one and only and dude - case sensitive
// str_ireplace - case insensitive version
 
JavaScript
 
var someString = "The one the only the dude";
someString = someString.replace('the', 'and');
/* 
 
The one and only the dude - case sensitive, only 
replaces first occurrence.
 
But since this method supports regular expressions,
one can replace all occurrences eg.
 
someString = someString.replace(/the/g,"and");
 
*/
 



No Entries Found

Post comment

Name *
Email
Title
Body *
Security code
*
* Required fields

Latest Articles

Top 5 Articles

Programming humor


Collection of funny programming articles
2006-10-08 14:23:43

How to create your own RSS Reader


It is very simple creating your own rss reader, the following article looks at a few methods of doing this.
2008-06-23 13:18:25

Javascript Reference: Dropdown


A quick reference about working with dropdown boxes (select element) in javascript.
2007-02-17 16:36:41

PHP: Snippets


Collection of PHP snippets
2010-05-22 00:06:45

Event driven programming in PHP


An article looking at adding some kind of event driven model to PHP 5
2008-07-28 12:48:09