Powershell修剪操作,如文件名,字符串,结尾,开始,空格

Powershell provides a lot of different string manipulation functions and features. Trim function is used to remove specified characters from string with different ways. In this tutorial we will look some of the trim examples.

Powershell提供了许多不同的字符串处理功能和特性。 Trim功能用于以不同方式从字符串中删除指定的字符。 在本教程中,我们将看一些修剪示例。

从开始和结束修剪空白 (Trim White Spaces From Start and End)

We will start by trimming given string or texts beginning and end white spaces. This operation generally done when a string operation is finished like extraction and be sure that string is clear and there is no unwanted characters.

我们将从修剪给定的字符串或文本开始和结束空白开始。 此操作通常在完成字符串操作(如提取)并确保字符串清晰且没有多余字符时完成。

$ "   This is my dirty text    ".trim()
Trim White Spaces From Start and End
Trim White Spaces From Start and End
从开始和结束修剪空白

修剪特定字符(Trim Specific Characters)

In some situations we may want to clear the text from specific characters. We only want to delete them. For example if we do not like s character 😉 we can remove this character from the string by giving s as parameter to the trim function.

在某些情况下,我们可能希望清除特定字符中的文本。 我们只想删除它们。 例如,如果我们不喜欢s字符😉,则可以通过将s作为参数给trim函数将其从字符串中删除。

从乞讨中删除字符 (Remove Characters From Begging)

We can delete characters from beginning of the text y specifying characters. We will use trimstart function and provide the characters. In this examples we will delete T character from start of the text.

我们可以从指定字符的文本y的开头删除字符。 我们将使用trimstart功能并提供字符。 在此示例中,我们将从文本开头删除T字符。

$ "This is my dirty text".Trimstart("T")
Remove Characters From Begging
Remove Characters From Begging
从乞讨中删除字符

从结尾删除字符(Remove Characters From End)

In previous step we have removed characters from start of the text. We can also delete characters from end of the text. We will use trimend function. We will remove the t character from end of the string.

在上一步中,我们从文本开头删除了字符。 我们还可以从文本末尾删除字符。 我们将使用trimend函数。 我们将从字符串末尾删除t字符。

$ "This is my dirty text".Trimend("t")
LEARN MORE  PHP Glob() Function To Match Path, Directory, File Names with Examples
了解更多PHP Glob()函数以示例匹配路径,目录,文件名

翻译自: https://www.poftut.com/powershell-trim-operation-like-filename-string-end-start-spaces/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值