我正在使用bash脚本进行测试.在我的测试中,我必须找到文件中第一次出现字符串的行号.我曾经尝试过"awk"和"grep",但是没有它们会返回值.
Awk的例子
#/!bin/bash
....
VAR=searchstring
...
cpLines=$(awk '/$VAR/{print NR}' $MYDIR/Configuration.xml
Run Code Online (Sandbox Code Playgroud)
这不会扩大$ VAR.如果我使用VAR的值它可以工作,但我想使用VAR
Grep的例子
#/!bin/bash
...
VAR=searchstring
...
cpLines=grep -n -m 1 $VAR $MYDIR/Configuration.xml |cut -f1 -d:
Run Code Online (Sandbox Code Playgroud)
这给出了错误行20:-n:command not found
我有一个有2列的excel表.第1列是名称,第2列是年龄.我想创建一个字典,其中name是key,age是value.这是代码,但它正在错误地创建字典.
keyValues = [x.value for x in worksheet.col(0)]
data = dict((x, []) for x in keyValues)
while curr_row < num_rows:
curr_row += 1
for row_index in range(1, worksheet.nrows): data[keyValues[row_index]].append(worksheet.cell_value(curr_row, 1))
Run Code Online (Sandbox Code Playgroud)
我希望有一个类似下面的字典来自2列excel表.
{'Ann': 12, 'Maria': 3, 'Robin': 4, 'NameN':N}
Run Code Online (Sandbox Code Playgroud) 我有两个字符串列表
l1 = {abc;xyz}
l2 = {lmn,xyz,abc}
Run Code Online (Sandbox Code Playgroud)
我想迭代这两个列表,看看l2是否包含l1中的所有元素,以及l1是否包含l2中的所有元素.
字符串的顺序无关紧要.请注意,字符串具有分隔符";"
我正在使用这两个for循环,但第二个for循环使索引超出范围.有一个更好的方法吗?
for (int i = 0; i < l1.Count; i++)
{
if (l1[i].Contains(l2[i])) {
Console.WriteLine("value {0} present in l1", l2[i]);
}
else {
Console.WriteLine("value {0} is not present in l1", l2[i]);
}
}
for (int i = 0; i < l2.Count; i++)
{
if (l2[i].Contains(l1[i])) {
Console.WriteLine("value {0} present in l2", l2[i]);
}
else {
Console.WriteLine("value {0} is not present in l2", l2[i]);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个存储mycustomer新请求信息的模型.在另一个历史模型中,我存储了客户的所有先前请求.在视图中我想接受新的订单,并看到他以前的订单,并在看到他以前的订单后提出一些食物.
这是我的模特......
public class CustomerFoodModel
{
public DateTime FoodRequestCreated { get; set; }
public string FoodRequestType { get; set; }
...
...
}
public class CustomerHistoryModel
{
public string Name { get; set; }
public DateTime FoodRequestCreated { get; set; }
public string FoodRequestType { get; set; }
...
...
}
Run Code Online (Sandbox Code Playgroud)
Helper.cs文件
public static CustomerFoodModel getCustomerDetails(int id) // id is loyalty card number
{
// get details from (cutomer) sql table
//store it in (CustomerFoodModel)
// check if it has …Run Code Online (Sandbox Code Playgroud)