1,一个长度为1000的字符串aibol_str, 由a-j共计10个字母随即组成。请用C#编程写主要函数
public string GenerateAibolStr(){}来实现。
2,请使用上述试题中的aibol_str字符串,完成如下函数。
///<summary>
///获取aibol_str中匹配的字符串个数
///</summary>
///<param name="s">需要匹配的字符串个数</param>
///<returns>aibol_str中包含的字符串s的数量</returns>
public int GetCount(string s){}
3,现有一个如下定义的XML文件<Dir name="root">
<Dir Name="project">
<File Name="test.sln"/>
<File Name="test.aspx.cs"/>
</Dir>
<File Name="makefile"/>
</Dir>
请使用递归算法,遍历所有的文件,并显示文件名及该文件对应的目录名称。
解决方案 »
- 错误:命名空间“ESRI.ArcGIS”中不存在类型或命名空间名称“TOCControl”。是否缺少程序集引用?
- 急,不使用绑定,DataGridView的批量更新问题!
- 求个在字符串中搜索字符串的正则表达式
- DataView如果实现过滤列的功能?
- 正则表达式(很简单)
- COOKIS总是获取上一次的值???
- foreach的一个小问题?
- C# 复制文件到window系统目录出错 学生狗求指导....
- 谁知道ConfigurationSettings.ConnectionStrings到底在哪里,头都大了!
- vs.net正式版5cd中都是bin,cue,md5文件,应该怎么安装?
- 代理、委托、事件
- C#调用C动态DLL问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GenerateAibolStr());
}
public static string GenerateAibolStr()
{
Random rnd = new Random();
StringBuilder sb=new StringBuilder();
while (sb.Length < 1001)
{
sb.Append((char)(rnd.Next(10) + 'a'));
}
return sb.ToString();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
string ss = GenerateAibolStr();
Console.WriteLine(ss);
int count = GetCount("a", ss);
Console.WriteLine(count);
} public static string GenerateAibolStr()
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
while (sb.Length < 1001)
{
sb.Append((char)(rnd.Next(10) + 'a'));
}
return sb.ToString();
}
/// <summary>
///获取aibol_str中匹配的字符串个数
/// </summary>
/// <param name="s">需要匹配的字符串 </param>
/// <returns>aibol_str中包含的字符串s的数量 </returns>
public static int GetCount(string s, string str) //str为原串
{
int count = 0;
while (str.IndexOf(s) != -1)
{
count++;
str = str.Substring(str.IndexOf(s) + 1, str.Length - str.IndexOf(s) - 1);
}
return count;
} }
}
private void Form1_Load(object sender, EventArgs e)
{
aibol_str = GenerateAibolStr();
int s = GetCount("abc");
Console.WriteLine("有{0}个匹配数", s.ToString());
}
public string GenerateAibolStr()
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
while (sb.Length < 1001)
{
sb.Append((char)(rnd.Next(10) + 'a'));
}
return sb.ToString();
}
/// <summary>
///获取aibol_str中匹配的字符串个数
/// </summary>
/// <param name="s">需要匹配的字符串个数 </param>
/// <returns>aibol_str中包含的字符串s的数量 </returns>
public int GetCount(string s)
{
int count = 0;
int start = 0;
while (aibol_str.IndexOf(s, start) != -1)
{
count++;
start = aibol_str.IndexOf(s, start)+1;
}
return count;
}