我想在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) 我试图将传入 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)
我正在使用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:/...