# NumPy - 字符串函数

1. `add()` 返回两个`str``Unicode`数组的逐个字符串连接
2. `multiply()` 返回按元素多重连接后的字符串
3. `center()` 返回给定字符串的副本，其中元素位于特定字符串的中央
4. `capitalize()` 返回给定字符串的副本，其中只有第一个字符串大写
5. `title()` 返回字符串或 Unicode 的按元素标题转换版本
6. `lower()` 返回一个数组，其元素转换为小写
7. `upper()` 返回一个数组，其元素转换为大写
8. `split()` 返回字符串中的单词列表，并使用分隔符来分割
9. `splitlines()` 返回元素中的行列表，以换行符分割
10. `strip()` 返回数组副本，其中元素移除了开头或者结尾处的特定字符
11. `join()` 返回一个字符串，它是序列中字符串的连接
12. `replace()` 返回字符串的副本，其中所有子字符串的出现位置都被新字符串取代
13. `decode()` 按元素调用`str.decode`
14. `encode()` 按元素调用`str.encode`

## `numpy.char.add()`

``````import numpy as np
print '连接两个字符串：'
print '\n'

print '连接示例：'
print np.char.add(['hello', 'hi'],[' abc', ' xyz'])
``````

``````连接两个字符串：
['hello xyz']

['hello abc' 'hi xyz']
``````

## `numpy.char.multiply()`

``````import numpy as np
print np.char.multiply('Hello ',3)
``````

``````Hello Hello Hello
``````

## `numpy.char.center()`

``````import numpy as np
# np.char.center(arr, width,fillchar)
print np.char.center('hello', 20,fillchar = '*')
``````

``````*******hello********
``````

## `numpy.char.capitalize()`

``````import numpy as np
print np.char.capitalize('hello world')
``````

``````Hello world
``````

## `numpy.char.title()`

``````import numpy as np
print np.char.title('hello how are you?')
``````

``````Hello How Are You?
``````

## `numpy.char.lower()`

``````import numpy as np
print np.char.lower(['HELLO','WORLD'])
print np.char.lower('HELLO')
``````

``````['hello' 'world']
hello
``````

## `numpy.char.upper()`

``````import numpy as np
print np.char.upper('hello')
print np.char.upper(['hello','world'])
``````

``````HELLO
['HELLO' 'WORLD']
``````

## `numpy.char.split()`

``````import numpy as np
print np.char.split ('hello how are you?')
print np.char.split ('TutorialsPoint,Hyderabad,Telangana', sep = ',')
``````

``````['hello', 'how', 'are', 'you?']
``````

## `numpy.char.splitlines()`

``````import numpy as np
print np.char.splitlines('hello\nhow are you?')
print np.char.splitlines('hello\rhow are you?')
``````

``````['hello', 'how are you?']
['hello', 'how are you?']
``````

`'\n'``'\r'``'\r\n'`都会用作换行符。

## `numpy.char.strip()`

``````import numpy as np
print np.char.strip('ashok arora','a')
``````

``````shok aror
['ror' 'dmin' 'jav']
``````

## `numpy.char.join()`

``````import numpy as np
print np.char.join(':','dmy')
print np.char.join([':','-'],['dmy','ymd'])
``````

``````d:m:y
['d:m:y' 'y-m-d']
``````

## `numpy.char.replace()`

``````import numpy as np
print np.char.replace ('He is a good boy', 'is', 'was')
``````

``````He was a good boy
``````

## `numpy.char.decode()`

``````import numpy as np

a = np.char.encode('hello', 'cp500')
print a
print np.char.decode(a,'cp500')
``````

``````\x88\x85\x93\x93\x96
hello
``````

## `numpy.char.encode()`

``````import numpy as np
a = np.char.encode('hello', 'cp500')
print a
``````

``````\x88\x85\x93\x93\x96
``````