跳至主要内容

trimprefix 函数

trimprefix 从给定字符串的开头移除指定的 前缀。如果字符串不以该前缀开头,则返回原始字符串。

示例

代码块
> trimprefix("helloworld", "hello")
world
代码块
> trimprefix("helloworld", "cat")
helloworld
  • trim 移除字符串开头和结尾的字符。
  • trimsuffix 移除字符串末尾的单词。
  • trimspace 移除字符串开头和结尾的所有类型空格。