sulhome / char-replace

replace character in a given string

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CharReplace module

This is a small module that does one thing which is replacing a character in a string.

API Documentation

Modules

charReplace

Classes

charReplace

charReplace

Kind: global class

new charReplace()

charReplace module

charReplace.replaceOne(source, charToFind, charToReplaceBy) ⇒ String

Replace one occurrence of charToFind with charToReplaceBy in source

Kind: instance method of charReplace Returns: String - source after character been replaced

Param Type Description
source String the string we want to manipulate
charToFind String the one character that will be searched in source
charToReplaceBy String the character that will replace charToFind

Example

// returns test;test
charReplace.replaceOne('test%test','%',';')

charReplace.replaceAll(source, charToFind:, charToReplaceBy:) ⇒ string

Replace ALL occurrence of charToFind with charToReplaceBy in source

Kind: instance method of charReplace Returns: string - source after character been replaced

Param Type Description
source String the string we want to manipulate
charToFind: string the one character that will be searched in source
charToReplaceBy: string the character that will replace charToFind

Example

// returns ;test;test;
charReplace.replaceAll('%test%test%','%',';')

charReplace.replaceByCounter(source, charToFind:, charToReplaceBy:, numberOfOccurrences) ⇒ string

Replace number of occurrence of charToFind with charToReplaceBy in source based on numberOfOccurrences

Kind: instance method of charReplace Returns: string - source after character been replaced

Param Type Description
source String the string we want to manipulate
charToFind: string the one character that will be searched in source
charToReplaceBy: string the character that will replace charToFind
numberOfOccurrences number the number of occurrences you want to replace

Example

// returns ;test;test%
charReplace.replaceByCounter('%test%test%','%',';',2)

About

replace character in a given string

License:MIT License


Languages

Language:JavaScript 100.0%