using System;class Sample {
public static void Main() { string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
string str = "Now is the time for all good men to come to the aid of their party.";
int start;
int at;
int count;
int end; start = str.Length-1;
end = start/2 - 1;
Console.WriteLine("All occurences of 't' from position {0} to {1}.", start, end);
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
Console.Write("The letter 't' occurs at position(s): "); count = 0;
at = 0;
while((start > -1) && (at > -1))
{
count = start - end; //Count must be within the substring.
at = str.LastIndexOf('t', start, count);
if (at > -1)
{
Console.Write("{0} ", at);
start = at - 1;
}
}
Console.Write("{0}{0}{0}", Environment.NewLine);
}
}
/*
This example produces the following results:
All occurences of 't' from position 66 to 32.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.The letter 't' occurs at position(s): 64 55 44 41 33我不明白的是 count的取值?
public static void Main() { string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
string str = "Now is the time for all good men to come to the aid of their party.";
int start;
int at;
int count;
int end; start = str.Length-1;
end = start/2 - 1;
Console.WriteLine("All occurences of 't' from position {0} to {1}.", start, end);
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
Console.Write("The letter 't' occurs at position(s): "); count = 0;
at = 0;
while((start > -1) && (at > -1))
{
count = start - end; //Count must be within the substring.
at = str.LastIndexOf('t', start, count);
if (at > -1)
{
Console.Write("{0} ", at);
start = at - 1;
}
}
Console.Write("{0}{0}{0}", Environment.NewLine);
}
}
/*
This example produces the following results:
All occurences of 't' from position 66 to 32.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.The letter 't' occurs at position(s): 64 55 44 41 33我不明白的是 count的取值?
解决方案 »
- textBox 值添加到数据库
- 在Bitmap上绘的图,在网页上显示是透明的,而保存成图片时只能是bmp格式并且背景会变成黑色?
- 谁有根据数据库中给出的流程用C#编写流程图的程序代码
- 语法错误 (操作符丢失) 在查询表达式 ''计科0501 ','1-2节','无'' 中。
- .Net漏洞或sql server or mysql漏洞
- 如何设置 LookUpEdit 弹出窗体的宽高
- 窗体属性statrposition
- 如何调用带dataset的dll中的dataset
- 按纽上的图片问题
- 阿土你进来,你的方法有问题!!!!!如果ASCII小于0,他会取绝对值,而不是真实值
- 刚用c#做的网站,谢谢大家指正,多提宝贵意见!
- 想做到像outlook那样,点击左边菜单,然后右边显示不同的form
例如字符串str="abcd"
那么str.LastIndexOf('c', 1, 3)
就代表str索引从1开始取,取3个字符,然后在里面查找字符'c'
也就是LastIndexOf('t', start, count)
count代表取多少个
count是向左的位数,也就是向左取多少个比如
string s = "123456789";
Console.WriteLine(s.LastIndexOf("9", 0, 2));//运行报错
string value,
int startIndex,
int count
)
参数
value
要查找的 String。 startIndex
搜索起始位置。 count
要检查的字符位置数。 返回值
如果找到该字符,则为 value 的索引位置;如果未找到该字符,则为 -1。如果 value 为 Empty,则返回值为 startIndex。