[英]SharePoint PowerShell script to trim new lines
I have a column in a SharePoint list with many newlines, including in the beginning of text. 我在SharePoint列表中有一列,其中包含许多换行符,包括文本开头。 I want to remove only first two newlines ie those in the beginning of the text as they are meaningless.
我只想删除前两个换行符,即文本开头的换行符,因为它们毫无意义。
Is there a way to do it with the trim function? 修剪功能有办法吗? I can't use replace as it will replace all the newlines.
我不能使用replace,因为它将替换所有换行符。 How do I do it?
我该怎么做?
String-objects have a TrimStart()
-Method that you could use to remove whitespace and newlines. 字符串对象具有
TrimStart()
方法,可用于删除空格和换行符。
$s = @"
test
"@
#Trim all whitespace and newlines before the text.
$s.TrimStart()
Output: 输出:
test
The solution above may remove too much. 上面的解决方案可能会去除太多。 To remove only two newlines (0-2 newlines), try the regex below.
要仅删除两个换行符(0-2个换行符),请尝试以下正则表达式。
$s = @"
test
"@
$s -replace '^[\n\r]{0,4}'
Output: 输出:
test
I'm not sure how you're input will look line (multi-line string vs. string-array, newline and/or Carriage Return etc.) so the answer may need to be modified. 我不确定您输入的内容看起来如何(多行字符串与字符串数组,换行符和/或回车符等),因此答案可能需要修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.