回答編集履歴
2
追記
test
CHANGED
@@ -13,3 +13,19 @@
|
|
13
13
|
print(s)
|
14
14
|
|
15
15
|
```
|
16
|
+
|
17
|
+
また、`.rstrip`の場合は`s = s.rstrip'\u0001\u0002~'`のように複数文字を指定し除去できます。
|
18
|
+
|
19
|
+
```Python
|
20
|
+
|
21
|
+
b = b'\x93\x8c\x8b\x9e\x93s \x90V\x8fh\x8b\xe6 \x90_\x8ay\x8d\xe2\x08\x07\x06\x05\x04\x03\x02\x01'
|
22
|
+
|
23
|
+
s = b.decode('shift-jis')
|
24
|
+
|
25
|
+
IGNORE = '\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008' # 複数の文字を指定
|
26
|
+
|
27
|
+
s = s.rstrip(IGNORE) # 右端のみ
|
28
|
+
|
29
|
+
print(s)
|
30
|
+
|
31
|
+
```
|
1
追記
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
`s.replace( '\u0004', '')`で
|
1
|
+
`s = s.rstrip('\u0004')`で右端のみ除去、あるいは`s.replace( '\u0004', '')`で間も含めて除去できます。
|
2
2
|
|
3
3
|
```Python
|
4
4
|
|
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
s = b.decode('shift-jis')
|
8
8
|
|
9
|
+
s = s.rstrip('\u0004') # 右端のみ
|
10
|
+
|
9
|
-
s = s.replace( '\u0004', '')
|
11
|
+
#s = s.replace( '\u0004', '') # 間も
|
10
12
|
|
11
13
|
print(s)
|
12
14
|
|