StringsHelper Module

Common string utilities and algorithms wrapped in a helper class.

class HMB.StringsHelper.StringsHelper(string)[source]

Bases: object

StringsHelper: Helper methods for common string operations.

Initialize with a string and call instance methods to perform queries and small algorithms (permutations, compression, palindrome-permutation checks, etc.). All public methods are designed to be small, self-contained, and documented inline.

Constructor for the StringsHelper class.

Parameters:

string (str) – The string to be used by the class.

__init__(string)[source]

Constructor for the StringsHelper class.

Parameters:

string (str) – The string to be used by the class.

GetString()[source]

Returns the string that was set during creating the object.

Returns:

The string that was set during creating the object.

Return type:

str

GetStringLength()[source]

Returns the length of the string that was set during creating the object.

Returns:

The length of the string that was set during creating the object.

Return type:

int

SetString(string)[source]

Sets the string to a new value.

Parameters:

string (str) – The new value for the string.

GetCharAt(index)[source]

Returns the character at the specified index.

Parameters:

index (int) – The index of the character to be returned.

Returns:

The character at the specified index.

Return type:

str

GetCharIndex(char)[source]

Returns the index of the specified character.

Parameters:

char (str) – The character to be searched for.

Returns:

The index of the specified character.

Return type:

int

GetCharCount(char)[source]

Returns the number of times the specified character appears in the string.

Parameters:

char (str) – The character to be searched for.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetCharCountFrom(char, index)[source]

Returns the number of times the specified character appears in the string

Parameters:
  • char (str) – The character to be searched for.

  • index (int) – The index from which the search will start.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetCharCountTo(char, index)[source]

Returns the number of times the specified character appears in the string

Parameters:
  • char (str) – The character to be searched for.

  • index (int) – The index to which the search will end.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetCharCountBetween(char, index1, index2)[source]

Returns the number of times the specified character appears in the string

Parameters:
  • char (str) – The character to be searched for.

  • index1 (int) – The index from which the search will start.

  • index2 (int) – The index to which the search will end.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetCharCountBetweenInclusive(char, index1, index2)[source]

Returns the number of times the specified character appears in the string

Parameters:
  • char (str) – The character to be searched for.

  • index1 (int) – The index from which the search will start.

  • index2 (int) – The index to which the search will end.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetCharCountBetweenExclusive(char, index1, index2)[source]

Returns the number of times the specified character appears in the string

Parameters:
  • char (str) – The character to be searched for.

  • index1 (int) – The index from which the search will start.

  • index2 (int) – The index to which the search will end.

Returns:

The number of times the specified character appears in the string.

Return type:

int

GetReverse()[source]

Returns the reverse of the string.

Returns:

The reverse of the string.

Return type:

str

GetReverseFrom(index)[source]

Returns the reverse of the string from the specified index.

Parameters:

index (int) – The index from which the reverse will start.

Returns:

The reverse of the string from the specified index.

Return type:

str

GetReverseTo(index)[source]

Returns the reverse of the string to the specified index.

Parameters:

index (int) – The index to which the reverse will end.

Returns:

The reverse of the string to the specified index.

Return type:

str

GetReverseBetween(index1, index2)[source]

Returns the reverse of the string between the specified indexes.

Parameters:
  • index1 (int) – The index from which the reverse will start.

  • index2 (int) – The index to which the reverse will end.

Returns:

The reverse of the string between the specified indexes.

Return type:

str

GetReverseBetweenInclusive(index1, index2)[source]

Returns the reverse of the string between the specified indexes.

Parameters:
  • index1 (int) – The index from which the reverse will start.

  • index2 (int) – The index to which the reverse will end.

Returns:

The reverse of the string between the specified indexes.

Return type:

str

GetReverseBetweenExclusive(index1, index2)[source]

Returns the reverse of the string between the specified indexes.

Parameters:
  • index1 (int) – The index from which the reverse will start.

  • index2 (int) – The index to which the reverse will end.

Returns:

The reverse of the string between the specified indexes.

Return type:

str

IsSubStringFrom(string)[source]

Returns True if the string is a substring of the string that was set during creating the object.

Parameters:

string (str) – The string to be searched for.

Returns:

True if the string is a substring of the string that was set during creating the object.

Return type:

bool

IsSubStringTo(string)[source]

Returns True if the string is a substring of the string that was set during creating the object.

Parameters:

string (str) – The string to be searched for.

Returns:

True if the string is a substring of the string that was set during creating the object.

Return type:

bool

IsRotationWith(string)[source]

Returns True if the string is a rotation of the string that was set during creating the object.

Parameters:

string (str) – The string to be searched for.

Returns:

True if the string is a rotation of the string that was set during creating the object.

Return type:

bool

GetPermutations()[source]

Returns a list of all the permutations of the string that was set during creating the object.

Returns:

A list of all the permutations of the string that was set during creating the object.

Return type:

list

IsPermutationOf(string)[source]

Returns True if the string is a permutation of the string that was set during creating the object.

Parameters:

string (str) – The string to be searched for.

Returns:

True if the string is a permutation of the string that was set during creating the object.

Return type:

bool

IsPalindromePermutation()[source]

Returns True if the string is a palindrome permutation of the string that was set during creating the object.

Returns:

True if the string is a palindrome permutation of the string that was set during creating the object.

Return type:

bool

IsUniqueCharacters()[source]

Returns True if the string has all unique characters.

Returns:

True if the string has all unique characters.

Return type:

bool

Urlify(strip=True)[source]

Returns the string with all spaces replaced by ‘%20’.

Parameters:

strip (bool) – If True, the string will be stripped before replacing the spaces.

Returns:

The string with all spaces replaced by ‘%20’.

Return type:

str

Compress()[source]

Returns the string compressed.

Returns:

The string compressed.

Return type:

str

IsOneEditOf(string)[source]

Returns True if the string is one edit of the string that was set during creating the object.

Parameters:

string (str) – The string to be searched for.

Returns:

True if the string is one edit of the string that was set during creating the object.

Return type:

bool