1. String Processing

Utility functions for string processing

yft.string.all_zh(x: str)[source]

Check whether a string is only comprised of Chinese characters

Parameters
xstr

String to check

Returns
bool

True if the input string has only Chinese characters, else False

yft.string.has_zh(x: str)[source]

Check whether a string contains Chinese characters

Parameters
xstr

String to check

Returns
bool

True if the input contains Chinese character, else False

yft.string.strF2H(x)[source]

全形轉半形

Parameters
xstr

含有全形字的字串

Returns
str

全為半形字的字串

Examples

>>> strF2H('aaa')
'aaa'
yft.string.strH2F(x)[source]

半形轉全形

Parameters
xstr

含有半形字的字串

Returns
str

全為全形字的字串

Examples

>>> strH2F('aaa')
'aaa'
yft.string.str_replace(x, charset: str, replacement='')[source]

Replace or remove multiple characters from a string

Parameters
xstr

String to replace

charsetstr

A string of characters to replace or remove from s

replacementstr, optional

Replacement string, by default ‘’, which is equivalent to removing characters in charset from s

Returns
str

The string with replacement inserted

Examples

>>> str_replace('abcde', 'ce', '_')
'ab_d_'
>>> str_replace('abcde', 'ce')
'abd'