Method for multi replace in strings
Project description
multireplace
Method for multi replace in strings
Method for replacing specified characters in a string with new characters. Single replacement and new characters are objects that are single words, parts of words, letters, special characters, or combinations thereof, enclosed in string literals.
There are three ways to specify replacement and new characters:
1) Replaced and new characters are grouped into lists or tuples of the same length.
In this case, each character being replaced is changed to
a new character located in the same place (having the same index).
2) One replacement character and one new character specified.
3) One new character and multiple replacement characters are specified,
grouped into a list or tuple.
In this case, each character being replaced is changed to the same new character.
When setting parameters in other ways than the above three, an valueError exception is thrown.
All values contained in the replacement_sumbols and new_sumbols will be converted to strings.
Installation
For installation:
pip install multireplace
Sample using
- To use, you need to create object
NewString. - For the received object, use the method
multireplace. The method returns a new string, but does not edit the original string. To save a new string, you must assign the result of the method execution to a variable. - After multiple replace, you can use all original methods for string.
from multireplace import multireplace
same_str = multireplace.NewString("I'll be back").multireplace(replacement_sumbols=['I', "'", 'll', 'k'],
new_sumbols=['We', ' ', 'will', 'k!'])
You can also use the method multireplace to remove multiple characters from a string.
To do this, specify the characters to be removed in the parameter replacement_sumbols
from multireplace import multireplace
same_str = multireplace.NewString("I'll be back").multireplace(replacement_sumbols=[' ', 'be', 'back'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multireplace-0.0.2.tar.gz.
File metadata
- Download URL: multireplace-0.0.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f97f296a4a6668ffc575f8d9e754fe7366a0372f4511103ce867c7a5538bfc7
|
|
| MD5 |
a7712386e7e7b50317debdd78a8be48c
|
|
| BLAKE2b-256 |
a794347ccfa164f74703d697b94d190e2a832d2eec90819e75b76ada338b7c78
|
File details
Details for the file multireplace-0.0.2-py3-none-any.whl.
File metadata
- Download URL: multireplace-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7ea34ccbbc3df445385d180a6221579e07e97747f018ac2d9020c3b41fcb3ac
|
|
| MD5 |
587bca112358a84881f209305da21595
|
|
| BLAKE2b-256 |
2129f15b4db1ea7f7a80da711710c3de1f46bbaac5e18f7ad64a185c0fdfba68
|