Brother zg159 and Brother Wunaaihe have wonderful and more general code. And using the file size to judge the number of bytes is a more convenient method.
At that time, when analyzing the three lines of code given by the owner, the code initially written according to the pattern naturally couldn't calculate the byte difference between Chinese characters and English characters. I also wanted to use the file size judgment, but out of sensitivity to generating temporary files, I only dealt with the three lines of code for 1F.
And besides Brother zh159's 8F using the file size to judge the number of bytes, there are other methods without generating temporary files. But the efficiency will be very low. In order to expand ideas and be familiar with different algorithms, everyone can try to use the following algorithm to judge Chinese characters and English characters.
1. Use for to list the characters to be matched, and once matched successfully, num+1.
2. After the FOR loop is executed, if the switch is not closed, it is judged as a Chinese character, so num+2.
3. After the entire nested loop is executed, calculate the value of num for space filling.
I hope everyone can write more wonderful code, use flexible ideas and more advanced algorithms to make up for the shortcomings of P processing script functions, and promote the development of this forum ^_^
业精于勤而荒于嬉,形成于思而毁于随。