I want to do the above with the UTF-8 character code.
If i just normally want to count all double-byte spaces,
str = '2019/11/2 today's date' pritnt str.count ('\ u3000')
From "2019/11/2 today's date"
This is the number of full-width blank strings before 2019/11/2
I want to return.
Can you tell me if there is any good way to do it?
Answer # 1
>>>import re >>>s = '2019/11/2 today's date' >>>re.match (r "\ u3000 *", s) .end () 3
re.matchis conveniently used to match only at the beginning of the string.
re --- Regular expression manipulation — Python 3.8.0 documentation
raw-strings is used,
\ u3000is recognized as a double-byte space by the regular expression parser, and since
*is used, it must match (If the first character is not a full-width space, a match object of
span = (0, 0)will be returned) is added as a reminder.
Answer # 2
An easy-to-understand method is to use a single character slice and look at the first character in order, and count until it is not a full-width space character or the string is exhausted. is.
Answer # 3
This is the way I came up with.
src = '2019/11/2 today's date' print ( len (src)-len (src.lstrip ('')) )
Answer # 4
It's a bit verbose in terms of processing, but ...
>>>import re >>>str = '2019/11/2 today's date' >>>print (len (re.split ('[^ \ u3000]', str) )) 3
Answer # 5
>>>import re >>>str = '2019/11/2 today's date' >>>re.search (r '[^ \ u3000]', str) .start () 3
- extract title and video count with python youtube api
- python - count by element with pivot_table in pandas
- python - how to count url clicks in django and record them in the db
- how to count days of the week python
- how to write to count the number of specific elements of dictionary values in python3
- count up when you press the python button
- python - i want to press the space key on the iframe
- python 3x - i don't understand the behavior of group by and count in pandas
- python - [django] i want to display the count number of child models
- python - django browsing count implementation
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin