Skip to content

Text

String Module for autopylot.This module contains functions for working with strings.

Examples:

>>> from autopylot import text
>>> text.get_alphabets(text="hello123:l;,")
'hellol'
>>> text.get_numbers(text="hello123:l;,")
'123
>>> text.remove_special_characters(text="hello123:l;,")
'hello123l'

The module contains the following functions:

  • get_alphabets(text): Extract only alphabets from the given string.
  • get_numbers(text): Extract only numbers from the given string.
  • remove_special_characters(text): Remove special characters from the given string.
  • get_substring(string, start, end, include_start=True, include_end=True, remove_trailing_whitespaces=True): Extract a substring from a string.

get_alphabets(text)

Extracts alphabets from the given string.

Parameters:

Name Type Description Default
text str

The string from which alphabets are to be extracted.

required

Returns:

Name Type Description
text str

Alphabets from the given string.

Examples:

>>> text.get_alphabets(text="hello123:l;,")
'hellol'

get_numbers(text)

Extracts alphabets from the given string.

Parameters:

Name Type Description Default
text str

The string from which numbers are to be extracted.

required

Returns:

Name Type Description
text str

Numbers extracted from the given string.

Examples:

>>> text.get_numbers(text="hello123:l;,")
'123'

get_substring(string, start, end, include_start=True, include_end=True, remove_trailing_whitespaces=True)

Extracts substring from a string.

Parameters:

Name Type Description Default
string str

The string from which substring is to be extracted.

required
start str

The starting word of the substring.

required
end str

The ending word of the substring.

required
include_start bool

Whether to include the starting word in the extracted substring.

True
include_end bool

Whether to include the ending word in the extracted substring.

True
remove_trailing_whitespaces bool

Whether to remove trailing whitespaces from the extracted substring.

True

Returns:

Name Type Description
substring str

The extracted substring.

Examples:

>>> get_substring(string="Hello Beautiful World. Today is a great day.", start="Hello", end="Today", include_start=True, include_end=False, remove_trailing_whitespaces=True)
'Hello Beautiful World.'

remove_special_characters(text)

Removes special characters from the given string.

Parameters:

Name Type Description Default
text str

The string from which special characters are to be removed.

required

Returns:

Name Type Description
text str

The string without special characters.

Examples:

>>> text.extract_only_alphabets(text="hello123:l;,")
'hello123l'