indextextreplace


Nameindextextreplace JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/indextextreplace
SummaryReplace specific substrings within a given string using index-based replacements
upload_time2023-10-14 23:43:48
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords string replace
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Replace specific substrings within a given string using index-based replacements

## Tested against Windows / Python 3.11 / Anaconda

## pip install indextextreplace

```python
index_text_replace(string: str, replacements: List[Tuple[int, int, str]]) -> str:
    r"""
    Replace specific substrings within a given string using index-based replacements.

    Args:
        string (str): The input string in which replacements will be made.
        replacements (List[Tuple[int, int, str]]): A list of replacement tuples, where each tuple
            consists of three elements:
            - Start index (int): The starting index of the substring to be replaced (inclusive).
            - End index (int): The ending index of the substring to be replaced (inclusive).
            - Replacement text (str): The text to replace the specified substring with.

    Returns:
        str: A modified string with the specified replacements applied.



    This function replaces substrings within the input `string` according to the provided
    `replacements` list. Each replacement is defined by a start index (inclusive), an end index
    (inclusive), and the replacement text. The replacement is applied to the specified substring
    within the string. The modified string is then returned.

    If the `replacements` list contains overlapping intervals, the behavior of the function is
    defined by the order of the replacements within the list. The last replacement in the list
    for a given index takes precedence.

    Note:
    - Indexing is 0-based.
    - The function does not modify the original input string and returns a new modified string.
    - If the start or end indices of a replacement are out of bounds, they are adjusted to
      the nearest valid index within the string.

    Raises:
        ValueError: If the end index of a replacement is less than the start index."""
		
from indextextreplace import index_text_replace
t = '''Parenthese (altgriechisch παρένθεσις parénthesis, deutsch ‚Einschub')'''
r = [(1, 2, 'XXXX'), (13, 14, 'YYYYY')]
index_text_replace(t, r)
# "PXXXXenthese (aYYYYYgriechisch παρένθεσις parénthesis, deutsch ‚Einschub')"

```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/indextextreplace",
    "name": "indextextreplace",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "string,replace",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8e/fa/c84ca15989a9ab0d86e23d3faebbce78f343aced1c1627408f41d49c5adc/indextextreplace-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Replace specific substrings within a given string using index-based replacements\r\n\r\n## Tested against Windows / Python 3.11 / Anaconda\r\n\r\n## pip install indextextreplace\r\n\r\n```python\r\nindex_text_replace(string: str, replacements: List[Tuple[int, int, str]]) -> str:\r\n    r\"\"\"\r\n    Replace specific substrings within a given string using index-based replacements.\r\n\r\n    Args:\r\n        string (str): The input string in which replacements will be made.\r\n        replacements (List[Tuple[int, int, str]]): A list of replacement tuples, where each tuple\r\n            consists of three elements:\r\n            - Start index (int): The starting index of the substring to be replaced (inclusive).\r\n            - End index (int): The ending index of the substring to be replaced (inclusive).\r\n            - Replacement text (str): The text to replace the specified substring with.\r\n\r\n    Returns:\r\n        str: A modified string with the specified replacements applied.\r\n\r\n\r\n\r\n    This function replaces substrings within the input `string` according to the provided\r\n    `replacements` list. Each replacement is defined by a start index (inclusive), an end index\r\n    (inclusive), and the replacement text. The replacement is applied to the specified substring\r\n    within the string. The modified string is then returned.\r\n\r\n    If the `replacements` list contains overlapping intervals, the behavior of the function is\r\n    defined by the order of the replacements within the list. The last replacement in the list\r\n    for a given index takes precedence.\r\n\r\n    Note:\r\n    - Indexing is 0-based.\r\n    - The function does not modify the original input string and returns a new modified string.\r\n    - If the start or end indices of a replacement are out of bounds, they are adjusted to\r\n      the nearest valid index within the string.\r\n\r\n    Raises:\r\n        ValueError: If the end index of a replacement is less than the start index.\"\"\"\r\n\t\t\r\nfrom indextextreplace import index_text_replace\r\nt = '''Parenthese (altgriechisch \u03c0\u03b1\u03c1\u03ad\u03bd\u03b8\u03b5\u03c3\u03b9\u03c2 par\u00e9nthesis, deutsch \u201aEinschub')'''\r\nr = [(1, 2, 'XXXX'), (13, 14, 'YYYYY')]\r\nindex_text_replace(t, r)\r\n# \"PXXXXenthese (aYYYYYgriechisch \u03c0\u03b1\u03c1\u03ad\u03bd\u03b8\u03b5\u03c3\u03b9\u03c2 par\u00e9nthesis, deutsch \u201aEinschub')\"\r\n\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Replace specific substrings within a given string using index-based replacements",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/indextextreplace"
    },
    "split_keywords": [
        "string",
        "replace"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc081ef3fea5ffae20055b1fa037df29edb23fce97fca2be0592fe188dd00b58",
                "md5": "2b5c2e4109d419986141a124a989c5e7",
                "sha256": "31f681400c6af06a7c32b6cff987e7104014132994db2b8991ae7f2bf75005e6"
            },
            "downloads": -1,
            "filename": "indextextreplace-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2b5c2e4109d419986141a124a989c5e7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5666,
            "upload_time": "2023-10-14T23:43:46",
            "upload_time_iso_8601": "2023-10-14T23:43:46.974356Z",
            "url": "https://files.pythonhosted.org/packages/cc/08/1ef3fea5ffae20055b1fa037df29edb23fce97fca2be0592fe188dd00b58/indextextreplace-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8efac84ca15989a9ab0d86e23d3faebbce78f343aced1c1627408f41d49c5adc",
                "md5": "15b37a140f61d41872a9f2caaceb4543",
                "sha256": "e889e6c457de2a9a4bf3ad6db109c79eeee0ae072f69e68b1c68f0c41f651efc"
            },
            "downloads": -1,
            "filename": "indextextreplace-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "15b37a140f61d41872a9f2caaceb4543",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3623,
            "upload_time": "2023-10-14T23:43:48",
            "upload_time_iso_8601": "2023-10-14T23:43:48.853054Z",
            "url": "https://files.pythonhosted.org/packages/8e/fa/c84ca15989a9ab0d86e23d3faebbce78f343aced1c1627408f41d49c5adc/indextextreplace-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-14 23:43:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "indextextreplace",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "indextextreplace"
}
        
Elapsed time: 0.16529s