我写了一个函数,/etc/bashrc因为我经常使用它,但现在它似乎不起作用:
function replaceall() {
find "$1" -type f -exec sed -i "s|$2|$3|g" {} \;
}
Run Code Online (Sandbox Code Playgroud)
直接运行时,我会做类似的事情:
find ./*/conf/production/*.conf -type f -exec sed -i "s|/home/user/sites|/var/www/vhosts|g" {} \;
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但是在使用该replaceall函数调用时它不起作用:
replaceall ./*/conf/production/*.conf "/home/user/sites" "/var/www/vhosts"
Run Code Online (Sandbox Code Playgroud)
注意:它在我使用时确实有效,replaceall . [...]这让我想知道,我是否遗漏了一些重要的语法?
我想知道是否有人可以帮助我.假设我有一个类型的元组(String,Int),以及这样的元组列表[("Strength",12),("Stamina",60),("Health",100)].如果我实际上不知道元组在列表中的顺序是什么,但只是包含字符串的某个元组存在,我如何使用该函数find来提取Int元组的值?("Stamina",60)"Stamina"
我试过了
value = snd ( find ("Stamina", _ ) stats )
Run Code Online (Sandbox Code Playgroud)
stats元组列表在哪里,value定义为
value :: a -> Int
Run Code Online (Sandbox Code Playgroud)
..但它不起作用:/所以任何想法?
我想用MySql数据库中的数据预填充多个Checkbox表单.
我的数据库数据:
id customer_id language_id preferred
1 10 150 yes
2 10 149 yes
Run Code Online (Sandbox Code Playgroud)
控制器"Preferredcustomerlanguages"中的查询
$clientlanguages = $this->Preferredcustomerlanguages
->find('list')
->select(['language_id'])
->where(['customer_id =' => $customer_id])
->where(['preferred =' => 'yes'])
->toArray()
;
Run Code Online (Sandbox Code Playgroud)
如果我用$ customer_id = 10开始查询,结果如下:
[
(int) 2 => (int) 2,
(int) 1 => (int) 1
]
Run Code Online (Sandbox Code Playgroud)
我以为查询会给我一个language_id的列表,我需要预先填写表单.
也许有人可以给我一个暗示,我想错了
根据这个MDN链接,find()方法采用一个可以带三个参数的回调函数:当前数组元素,当前数组元素的索引以及调用该方法的数组.
所以:
var r = [2, 9, 11]; console.log(r.find(function(e, i, r) {
if (e % 2 === 0)
return e; }))
Run Code Online (Sandbox Code Playgroud)
如我所料,返回2.
然而:
var r = [2, 9, 11];
console.log(r.find(function(e, i, r) {
if (e % 2 === 0)
return i;
}))
Run Code Online (Sandbox Code Playgroud)
return undefined(当我期望0时),
和
var r = [2, 9, 11];
console.log(r.find(function(e, i, r) {
if (e % 2 === 0)
return r;
}))
Run Code Online (Sandbox Code Playgroud)
返回2(当我期望[2,9,11]).
有人可以解释我没有正确理解的内容吗?
Json test = Json.emptyArray;
test ~= "aaa";
test ~= "bbb";
test ~= "ccc";
writeln(test);
Run Code Online (Sandbox Code Playgroud)
输出: ["aaa","bbb","ccc"]
但是如何检查这个数组是否有元素?我无法想象如何使用canFindJSON数组.我正在使用振动的json模块.
if(test.get!string[].canFind("aaa"))
{
writeln("founded");
}
Run Code Online (Sandbox Code Playgroud)
不起作用: Got JSON of type array, expected string.
如果这样做:
if(test.get!(string[]).canFind("aaa"))
{
writeln("founded");
}
Run Code Online (Sandbox Code Playgroud)
Error: static assert "Unsupported JSON type 'string[]'. Only bool, long, std.bigint.BigInt, double, string, Json[] and Json[string] are allowed."
使用to!string和toString方法所有工作:
Json test = Json.emptyArray;
test ~= "aaa";
test ~= "bbb";
test ~= "ccc";
writeln(to!string(test));
if(test.toString.canFind("aaa"))
{
writeln("founded");
}
Run Code Online (Sandbox Code Playgroud)
但如果我在foreach中做到这一点: …
我想在Notepad ++中只找到并替换标记的行.我怎样才能做到这一点?
示例:
我使用"查找和替换 - 标记"选项卡标记了以下文本的行(包含XYZ).标记后,我想将"问题"字替换为我标记的行中的另一个字.
XYZ THIS IS A SAMPLE TO EXPLAIN MY PROBLEM.
SAMPLE TO EXPLAIN MY PROBLEM
XYZ EXPLAIN TO MY PROBLEM
MY PROBLEM
XYZ PROBLEM
Run Code Online (Sandbox Code Playgroud)
或者如何选择/突出显示标记的线条.如果我找到此功能,我的问题将得到解决(使用IN SELECTION选项).
我试着在这个问题上找到一个类似的问题.我想知道是否有人可以用我的代码指出这个漏洞.我有一个类型类List调用,该类看起来像这样:statusesStatus
public class Status
{
public int StatusID { get; set; }
public string StatusDescr { get; set; }
public string StatusType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我从SQL检索数组/记录列表,并希望使用已知的StatusID找到StatusDescr:
List<Status> statuses = Status_Get(inputAction, dataDef);
var inputStatusID = fooData["StatusID"];
string statusDescr = Array.Find<List<Status>>(statuses, item => item.StatusID == inputStatusID).StatusDescr;
Run Code Online (Sandbox Code Playgroud)
但我item.StatusID在第3行收到错误说:
'List<Status> does not contain a definition for 'StatusID' and no extension method 'StatusID' accepting a first argument of type 'List<Status>' could be found'
显然这是因为StatusID存在于Status类型中,而不是List<Status>.如果我将其更改为Array.Find<Status> …
我相信这是一个直截了当的问题,希望我不会感到生气。编写代码以在C驱动器中找到名为text.txt的文件
If IO.File.Exists("C:\text.txt") Then
MessageBox.Show("Found text file")
Else
MessageBox.Show("Not Found")
End If
Run Code Online (Sandbox Code Playgroud)
当位于子文件夹中时,找不到“ C:\ text.txt”。为此应使用什么语法?
我在寻找解决方案上花了很多时间,因此在这里提出了一个简单的问题。
谢谢!
我有一个矩阵,
A = [ 0 0 0 0 0 0 1 1 1 1 0 0; 0 0 0 0 0 1 1 1 1 0 0 0; 0 0 0 0 0 0 1 1 1 1 0 0]
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何在每一行中找到第一个'1'.我想输出将显示如下:
B = [7; 6; 7]
Run Code Online (Sandbox Code Playgroud)
这意味着,对于第一行,在第7列中找到数字1,在第6列中找到第二行,依此类推.
我需要检查子字符串是否是特定字符串的一部分。子字符串为“ AAA”,如果在给定字符串中找到它,则必须返回True。如果不在字符串中,则必须返回False
def isResistent(virus):
gen = "AAA"
if gen in virus:
print("True")
else:
print("False")
isResistent('GCAAGCTGGTCGTGAAAGCT')
Run Code Online (Sandbox Code Playgroud)
它返回True或False,但是除了True或False之外,它还首先给出索引号或其他内容。当我多次运行该程序时,它返回:
输出:
2
True
1
True
2
True
4
True
0
True
Run Code Online (Sandbox Code Playgroud)
是否只能打印True或False?