1.拿到京东的页而html数据,把里面的一级菜单给抓取出来,然后将每一个级菜单的数据存到数组中最后将数组转成json字符串放到json. txt文件中一个数组中放着很多对象,一个对象里面就有一个字段firstMenue-个数组
using LitJson
using System.Net
using System.Text
using System.Text.RegularExpressions
namespace ConsoleApp1025
{
public class Menu
{
//使用一个静态方法帮我们创建对象
public Menu()
{
this.firstMenu = FirstMenu
}
public List<string> firstMenu
private static List<string> FirstMenu
public static Menu getMenu(List<string> MenuList)
{
FirstMenu = MenuList
return new Menu()
}
}
internal class Program
{
static void Main(string[] args)
{
List<Menu> MyMenu = new List<Menu>()
//昨天讲了json,如何转成json字符串,还有怎么拿到json数据转成对应的数组或者对象,正则收官
//1.拿到京东的页而html数据,把里面的一级菜单给抓取出来,然后将每一个级菜单的数据存到数组中
//最后将数组转成json字符串放到json. txt文件中一个数组中放着很多对象,一个对象里面就有一个字段firstMenue-个数组
/*WebClient wc = new WebClient()
wc.Encoding = Encoding.UTF8
string file = File.ReadAllText("./1.html")
MatchCollection matches = Regex.Matches(file, "<a.*>(.*)</a>")
foreach(Match i in matches)
{
Console.WriteLine(i.Groups[1].Value)
}
Console.ReadKey()
//应为换行影响我们去提取 不如利用换行去帮助我们
//干脆把</li>后面加上换行,每次去匹配的内容是没有换行符的
//利用这个特点 我想匹配谁就给谁加换行符
//先拿到数据
string files = File.ReadAllText("./1.html")
//先去掉所有的换行符,给</li>后面加一个\n
files = files.Replace("\n", "")
string pattern1 = "<li\\s+class=\"cate_menu_item\".+?</li>"
string pattern2 = "<a.+class=\"cate_menu_lk\".+>(.+)</a>"
MatchCollection matches = Regex.Matches(files, pattern1)
foreach (Match i in matches)
{
if (i.Success)
{
List<string> MenuList = new List<string>()
//匹配每一组a中的数据
string file = Convert.ToString(i).Replace("</a>", "</a>\n")
MatchCollection menuMatches = Regex.Matches(file, pattern2)
foreach(Match j in menuMatches)
{
MenuList.Add(j.Groups[1].ToString())
}
//将列表赋值给对象的一个字段,将对象放到列表中
MyMenu.Add(Menu.getMenu(MenuList))
}
}
//转json格式
string json = JsonMapper.ToJson(MyMenu)
File.WriteAllText("./1.TXT", json)
}
}
}


哈希表
using System.Collections;
namespace 哈希表
{
internal class Program
{
static void Main(string[] args)
{
Hashtable table = new Hashtable();
table.Add("name", "林宇隆");
table.Add("id",123);
table["name"] = 3;
Console.WriteLine(table["name"]);
foreach(DictionaryEntry i in table)
{
Console.WriteLine(i.Key);
Console.WriteLine(i.Value);
}
foreach(var i in table.Keys)
{
Console.WriteLine(i);
}
foreach(var i in table.Values)
{
Console.WriteLine(i);
}
table.Remove("name");
Console.WriteLine(table.Contains("name"));
Console.WriteLine(table.ContainsKey("name"));
Console.WriteLine(table.ContainsValue("林宇隆"));
}
}
}

链表
namespace 链表1026night
{
public class LinkList<T>
{
public LinkNode<T> head;
public LinkNode<T> last;
public void Add(T value)
{
LinkNode<T> node = new LinkNode<T>();
node.value = value;
if (head == null)
{
head = node;
last = node;
}
else
{
last.nextNode = node;
last = node;
}
}
public LinkNode<T> Find(T value)
{
LinkNode<T> node = head;
while (node != null)
{
if (node.value.Equals(value))
{
return node;
}
node = node.nextNode;
}
return null;
}
public void Remove(T value)
{
LinkNode<T> node = head;
while (node != null)
{
if (node.nextNode == null)
{
head = null;
last = null;
return;
}
else
{
if (head.value.Equals(value))
{
head = head.nextNode;
}
}
if (node.nextNode.value.Equals(value))
{
if (last.value.Equals(value))
{
node.nextNode = null;
last=node;
}else
{
node.nextNode = node.nextNode.nextNode;
}
return;
}
node = node.nextNode;
}
return;
}
}
public class LinkNode<T>
{
public T value;
public LinkNode<T> nextNode;
public LinkNode<T> previous;
}
internal class Program
{
static void Main(string[] args)
{
LinkList<string> list = new LinkList<string>();
list.Add("fdjlkfld");
Console.WriteLine(list.Find("fdjlkfld").value);
list.Remove("fdjlkfld");
Console.WriteLine(list.Find("fdjlkfld")==null);
}
}
}
