Added method stringByReplacingOccurrencesOfStringWithString and testcase for the same.

This commit is contained in:
vijaykiran
2008-09-17 23:17:56 +02:00
parent 6c2a50f767
commit 9a397bf03f
2 changed files with 43 additions and 0 deletions
+31
View File
@@ -232,6 +232,7 @@ var CPStringHashes = new objj_dictionary();
if (difference) string += substring.substr(difference + substring.length);
}
//Dividing Strings
/*
Tokenizes the receiver string using the specified
delimiter. For example, if the receiver is:
@@ -351,6 +352,36 @@ var CPStringHashes = new objj_dictionary();
return CPMakeRange(location, location == CPNotFound ? 0 : aString.length);
}
//Replacing Substrings
/*
Returns a new string in which all occurrences of a target string in the reciever are replaced by
another given string.
@param target The string to replace.
@param replacement the string with which to replace the <pre>target<pre>
*/
- (CPString)stringByReplacingOccurrencesOfString:(CPString)target withString:(CPString)replacement
{
return self.replace(new RegExp(target, "g"), replacement);
}
/*
- (CPString)stringByReplacingOccurrencesOfString:(CPString)target
withString:(CPString)replacement
options:(int)options
range:(CPRange)searchRange
{
//TODO :Vijay implement the method
}
- (CPString)stringByReplacingCharactersInRange:(CPRange)range withString:(CPString)replacement
{
//TODO :Vijay implement the method
}
*/
// Identifying and comparing strings
/*
Compares the receiver to the specified string.
+12
View File
@@ -2,6 +2,18 @@ import <Foundation/CPString.j>
@implementation CPStringTest : OJTestCase
- (void)testStringByReplacingOccurrencesOfStringWithString
{
var expectedString = @"hello world. A new world!";
var dummyString = @"hello woold. A new woold!";
var actualString = [dummyString stringByReplacingOccurrencesOfString:@"woold" withString:@"world"];
[self assertTrue:(expectedString === actualString)
message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
}
- (void)testStringByAppendingFormat
{
var format = @"%d X %d = %d";