是否有可能有包含函数发现如果字符串包含2个字以上?这就是我想要做的:
string d = "You hit someone for 50 damage";
string a = "damage";
string b = "someone";
string c = "you";
if(d.Contains(b + a))
{
Console.WriteLine(" " + d);
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
当我运行此,控制台窗口刚刚关闭的真快,而不显示任何内容.
而另一个问题:如果我一想添加多少损害的是,这将是获得该号码,把它变成一个最简单的方法TryParse?
我有一个foreach声明,我从文本文件中经过几行,在那里我已经修剪并整理出我需要的行.我想要做的是计算相同字符串的出现次数.我该怎么做呢?
这是我的代码.这是if我被困的第二个陈述:
foreach (string line in lines.Where(l => l.Length >= 5))
{
string a = line.Remove(0, 11);
if ((a.Contains(mobName) && a.Contains("dies")))
{
mobDeathCount++;
}
if (a.Contains(mobName) && a.Contains("drops"))
{
string lastpart = a.Substring(a.LastIndexOf("drops"));
string modifiedLastpart = lastpart.Remove(0, 6);
}
Run Code Online (Sandbox Code Playgroud)
下面是一些线条的样子:
一袋硬币
siog白兰地
一袋硬币
一袋硬币
Cath Shield
破烂的卷轴
所以我想要做的是计算有3行硬币袋.但我需要做到这一点,它可以成为一切,这是一个巨大的下降列表.所以不能添加所有的em,需要太长时间
编辑
private static void Main()
{
int mobDeathCount = 1;
int lootCheckCount = 1;
string[] lines =
System.IO.File.ReadAllLines(@"C:\Users\Michael\Documents\Electronic Arts\Dark Age of Camelot\chat.log");
Console.WriteLine(
"Enter which mob you want …Run Code Online (Sandbox Code Playgroud) while (fscanf(ifp, " %d %d kl. %d %s - %s %d - %d %d\n", &round, &date, &clock, teeam, &goals, &attendance)
Run Code Online (Sandbox Code Playgroud)
我应该知道这一点,但是第二个%d应该将日期导入我的变量,比如20.20.2012但是我只得到前20个而不是其余的.
谢谢 :)
我有一个文本文件,我正在搜索,我想跳过每行中的10个第一个字符.
每行开头[10:16:01],这就是我想要跳过的内容,我想在行中找到下一个数字并将数字加在一起.
这是我到目前为止所做的
foreach (string line in lines)
{
string a = line.Remove(0, 10);
if (a.Contains("whateverimsearchingfor"))
{
string resultString = Regex.Match(a, @"\d+").Value;
int result = Int32.Parse(resultString);
total += result
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
对不起,当我尝试构建时,我得到:
ArgumentOutOfRangeException是未处理的索引,count必须引用字符串中的位置
它指向字符串a = line.remove(0,10)
希望这就够了.
我有一个字符串与字符串和int我想解析字典字符串和内联到一个HTML表格,如果可能的话?
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<string, int> userMediaList = new Dictionary<string, int>();
userMediaList.Add("Die Hard", 5);
userMediaList.Add("Die Hard II", 3);
userMediaList.Add("Die Hard III", 2);
userMediaList.Add("Ringenes Herre", 4);
userMediaList.Add("Ringenes Herre II", 1);
userMediaList.Add("Ringenes Herre III", 5);
var sortUserMediaList = from entry in userMediaList orderby entry.Value ascending select entry;
}
Run Code Online (Sandbox Code Playgroud)
所以我想要的是将它添加到网站上的表格中.
因此,对于表格中的每个框,将显示电影的名称和电影的评级.