最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google sheets - Remove space after line before new line - Stack Overflow

programmeradmin2浏览0评论

I need to remove the space before the new line, within the cell. I know TRIM should work for this, but I believe it only deletes the very last space of the string.

So I probably need to replace space+CHAR(10) into CHAR(10) only. But I'm not sure which formula is best for this. Any ideas?

I need to remove the space before the new line, within the cell. I know TRIM should work for this, but I believe it only deletes the very last space of the string.

So I probably need to replace space+CHAR(10) into CHAR(10) only. But I'm not sure which formula is best for this. Any ideas?

Share Improve this question edited Jan 30 at 11:00 jonrsharpe 122k30 gold badges267 silver badges474 bronze badges asked Jan 30 at 10:53 AnneAnne 191 silver badge1 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 2

You can try these Formulas using REGEXREPLACE:

=REGEXREPLACE(A1, "\s+\n", CHAR(10))

Or

=REGEXREPLACE(A1, "\s+($|\n)", "$1")

Also, you can try using REDUCE:

=REDUCE(,SPLIT(A1, CHAR(10)), LAMBDA(a,c, JOIN(REGEXREPLACE(c,"\s[^ ]*$",""),a,CHAR(10))))

Use split() to break text into parts at newlines, trim() to remove spaces at the start and end of lines and to replace repeated spaces within lines, and finally join() to put the parts back together, like this:

=join(char(10), sort(trim(split(A1, char(10)))))

The sort() function is only used to array enable the trim() and doesn't actually sort anything in this context.

See split(), trim() and join().

发布评论

评论列表(0)

  1. 暂无评论