小编lbu*_*tlr的帖子

如果charAt等于字符列表

我想在Javascript中使用以下内容

如果str.charAt(index)(在集合中){".",",","#","$",";",":"}

是的,我知道这一定很简单,但我似乎无法正确理解语法.我现在拥有的是什么

theChar = str.charAt(i);
if ((theChar === '.') || (theChar === ',') || (theChar === ... )) {
  // do stuff
}
Run Code Online (Sandbox Code Playgroud)

这有效,但必须有更好的方法.

编辑:我做了这个,但不确定它是否良好:

var punc = {
    ".":true,
    ",":true,
    ";":true,
    ":":true
};

if (punc[str.charAt[index]) { ...
Run Code Online (Sandbox Code Playgroud)

javascript charat

4
推荐指数
1
解决办法
6075
查看次数

$0 中的 awk gsub 也更改变量

我试图将传入 awk 的文本分配给一个变量,然后更改 $0 ,然后输出原始字符串和更改后的字符串:

# echo "This is a test" |awk '{text=$0; gsub(/ /,"%20"); print $text; print $0;}' 
This%20is%20a%20test
This%20is%20a%20test
Run Code Online (Sandbox Code Playgroud)

但我期待着它的回归

This%20is%20a%20test
This is a test
Run Code Online (Sandbox Code Playgroud)

尝试更改 #text 变量会产生同样的效果。

# echo "This is a test" |awk '{text=$0; $text gsub(/ /,"%20"); print $text; print $0;}' 
This%20is%20a%20test
This%20is%20a%20test
Run Code Online (Sandbox Code Playgroud)

运行 DSM 6.2 的 Synology 上的 GNU Awk 4.1.3、API:1.1(GNU MPFR 3.1.3、GNU MP 6.0.0)

variables awk gsub

3
推荐指数
1
解决办法
4315
查看次数

如何通过管道将命令输出传递给curl

我正在使用curl 将一些urlencoded 内容发布到URL,并且我希望curl 命令的内容来自管道。基本上...

... | curl -s --data-urlencode '{\"text\":\"$PIPE_RESULT\"}' http://...

我认为 $0 可能有效,但我收到 invalid_payload 错误,其简单文本如下:

echo "http://www.example.com" | curl -s --data-urlencode '{"text\":\"$0\"}' https:/...

curl pipe

1
推荐指数
1
解决办法
2437
查看次数

标签 统计

awk ×1

charat ×1

curl ×1

gsub ×1

javascript ×1

pipe ×1

variables ×1