mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-07 11:17:12 +00:00
Added method stringByReplacingOccurrencesOfStringWithString and testcase for the same.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user