Skip to main content

Get the context around an index location in a string

Project description

stringcontext

Simple Python library functions for getting the context around an index location in a string.

This library was designed to handle retrieving a given amount of context around, before, or after an index location in a string.

  • context_after: returns the string of n characters after the given index, or until the end of the string.
  • context_before: returns the string of n characters before the given index, or until the beginning of the string.
  • context: returns the full string of the context before, after, and including the character at index.

The code handles out of range issues on both ends of the string.

Based on the grep program's -C option switch

Usage

import stringcontext

string = "Hello World test"
index = 5 # the space char

c = stringcontext.context(string, index, 5)
# "Hello World"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for stringcontext, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size stringcontext-1.0.0-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size stringcontext-1.0.0.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page