我在Bash中有一个字符串:
string="My string"
Run Code Online (Sandbox Code Playgroud)
如何测试它是否包含另一个字符串?
if [ $string ?? 'foo' ]; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
??我的未知运营商在哪里?我是否使用echo grep?
if echo "$string" | grep 'foo'; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
这看起来有点笨拙.
我想编写一个Unix shell脚本,如果另一个字符串中有一个字符串,它将执行各种逻辑.例如,如果我在某个文件夹中,请分支.有人可以告诉我如何做到这一点?如果可能的话,我想让这不是特定于shell的(即不仅仅是bash),但如果没有别的方法可以做到这一点.
#!/usr/bin/env sh
if [ "$PWD" contains "String1" ]
then
echo "String1 present"
elif [ "$PWD" contains "String2" ]
then
echo "String2 present"
else
echo "Else"
fi
Run Code Online (Sandbox Code Playgroud) 我知道有Alt+ Enter组合将单个String提取到字符串资源.但我想知道有什么东西可以将我的项目的所有字符串提取到字符串资源中吗?
如果我制作其中一个,Android工作室也不会将相同的String制作成字符串资源.
String s = "Hello World";
String s2 = "Hello World";
Run Code Online (Sandbox Code Playgroud)
例如.我将"Hello World"创建为字符串资源,另外还在项目中同样保存硬编码.
String s = getString(R.string.helloworld);
String s2 = "Hello World";
Run Code Online (Sandbox Code Playgroud)
如果有人知道这样的事情.