- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很惊讶这个扩展:
$ echo "${foo:~abc}"
当 foo
未设置时产生空字符串。我预计它会像这样解析:
$ echo "${foo:(~abc)}"
并产生字符串“~abc”。但是相反,我发现如果我确实定义了
$ foo='abcdefg'
$ echo "${foo:~abc}"
g
事实上,它是在算术上下文中取“abc”并做的。 “${foo:~0}”
。同样
$ foo='abcdefg'
$ echo "${foo:~3}"
defg
它获取扩展的最后 n+1 个字符。我查看了联机帮助页的“参数扩展”部分。我看那里没有提到代字号。 Bash Hackers Wiki只提到波浪号作为(也未记录的)大小写修饰符。
此行为至少可以追溯到 3.2.57。
我只是错过了记录这种形式的子字符串扩展的地方,还是根本没有记录?
最佳答案
它并非未记录(您可能将 ${foo:~abc}
与 ${foo-~abc}
混淆了)。
${parameter:offset}
${parameter:offset:length}
Substring Expansion. Expands to up to length characters of the
value of parameter starting at the character specified by off-
set. [...] If length is omitted, expands to the substring of the
value of parameter starting at the character specified by offset
and extending to the end of the value. length and offset are
arithmetic expressions (see ARITHMETIC EVALUATION below).
这里,~abc
是展开的偏移域,~
是算术表达式中的按位取反运算符。未定义的参数在算术表达式中的计算结果为 0,并且 ~0 == -1
。
关于Bash tilde *substring* 扩展 - 未记录的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31703040/
**摘要:**下面就来给大家介绍这三个函数在字符截取时的一些用法与区别。 本文分享自华为云社区《GaussDB(DWS)中的字符截取三胞胎》,作者:我站在北方的天空下 。 在GaussDB(DWS)中
我对 JSTL 标记库前缀“fn”有疑问(Eclipse Luna 中的 webapp 开发)。 我的 taglibs.jspf 如下: 和 web.xml : *.
我正在使用转发器控件和数据绑定(bind)器将数据库中的数据显示到我的网站。示例:DataBinder.Eval(Container, "DataItem.title") 有时文字太长通常我使用 su
The second argument to substring is the index to stop at (but not include), but the second argument
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
假设我想返回一些 needle char 'x' 之后的所有字符,来自: $source_str = "Tuex helo babe". 通常我会这样做: if( ($x_pos = strpos($
谁能告诉我,Django 模板中是否存在 PHP 中的 substr ( http://pl2.php.net/manual/en/function.substr.php ) 之类的方法? 最佳答案
有什么区别 alert("abc".substr(0,2)); 和 alert("abc".substring(0,2)); 他们似乎都输出“ab”。 最佳答案 区别在于第二个参数。 substrin
我正在尝试编写一个函数,其中一列包含一个子字符串并且不包含另一个子字符串。 在下面的示例中,如果我的行包含“某些项目”并且不包含“开销”,我希望我的函数返回 1。 row| example strin
为什么这里 substr-rw 会切断尾随的 6? #!/usr/bin/env perl6 use v6; my $str = '123'; $str ~= '.' x 30; $str ~= '4
例子如下: a = "one two three four five six one three four seven two" m = re.search("one.*four", a) 我想要的是
来自 this question ,我们对这两个变体进行基准测试, substr( $foo, 0, 0 ) = "Hello "; substr( $foo, 0, 0, "Hello " ); 在
在我使用之前: entityManagerFactory.createQuery("select p FROM Pays p where SUBSTRING(p.libeleClient, 0,1)
substring() 和 substr() 在 MySQL 中执行时给出相同的结果。那么,它们是一样的吗?其中哪一个应该优先于另一个? 最佳答案 没有区别。阅读 manual ! 关于mysql -
在我使用之前: entityManagerFactory.createQuery("select p FROM Pays p where SUBSTRING(p.libeleClient, 0,1)
substring() 和 substr() 在 MySQL 中执行时给出相同的结果。那么,它们是一样的吗?其中哪一个应该优先于另一个? 最佳答案 没有区别。阅读 manual ! 关于mysql -
我的日期格式是这样的 2010-11-15 04:28:31 我只想选择 2010-11-15 而不是 2010-11-15 04:28:31 , 使用MYSQL查询, 从 TBL 中选择 SUBST
下面您可能会看到 xslt 代码来生成单选按钮。它适用于 Firefox 和 Opera,但不适用于 arora(使用 webkit 引擎)。简而言之,我没有尝试任何其他浏览器使用 webkit 引擎
我正在尝试向字符串中插入一个单词。为此,我使用 slice 函数,但它删除了我的空格。我还尝试了 substring 和 substr。我还查看了代码,它使用数组操作,我相信这就是问题所在。我能做什么
我是一名优秀的程序员,十分优秀!