开发者

How can i use gsub to replace "0" (only)

gsub('$0\n','') 开发者_如何转开发isn't working

I would prefer something similar. I want: (note the 10 and 20 have to work with 0 not being replaced in them).

If I have:
23
12
 0
15
 9
 0
10
20
 0


I want:
23
12

15
 9

10
20


You may want to convert this to an array to re-process it, but the same thing can be done with a regular expression:

string.gsub(/^\s+0+$/m, '')

The /m part is key and it makes the expression operate in multi-line mode, that is ^ and $ refer to the beginning and ending of a line, not the beginning and ending of the string as is usually the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜