【学习日志】2022.08.23 c# split方法 火车票售票系统 地图

c# split方法

1.对单个字符进行分解  分割的是字符,不是字符串,只能用单引号 split('xxxx')

            string s = string.Empty;
            string str = "aascaacbbcssc";
            string[] arr = str.Split('c');
            foreach (var i in arr)
            {
                s += i + " ";
            } 
// s:aas aa bb ss  

2.对多个字符进行分割

            string s = string.Empty;
            string str = "abcdeabcdeabcde";
            string[] arr = str.Split( new char[3] { 'c', 'd', 'e' });
            foreach (var i in arr)
            {
                s += i + " ";
            } 
//s:ab   ab   ab 

3.正则表达式进行分割

            string s = string.Empty;
            string str = "aaajsbbbjsccc";
            string[] brr = Regex.Split(str, "js", RegexOptions.IgnoreCase);            
            foreach (var i in brr)
            {
                s += i + " ";
            } 
//s:aaa bbb ccc 

split重载方法

c91be0a34a17476983b69fb7967f3ce9.png

方法调用

方法二: String.Split(Char[],Int32)
 
string str = "aaatbbscctdd";
 
string []strArray = str.Split(new char[]{'t',2});
//只切割成2份(result :"aaa" "bbscctdd")
 
方法三:String.Split(Char[],StringSplitOptions)
 
string str = "aaatbbscctddt";
 
string []strArray = str.Split(new char[]{'t',StringSplitOptions.RemoveEmptyEntries});
//去除空元素(result :"aaa" "bbscc" "dd")
 
string []strArray = str.Split(new char[]{'t',StringSplitOptions.None});
//保留空元素(result :"aaa" "bbscc" "dd" “”) 
 
方法四:String.Split(String[],StringSplitOptions)
 
string str = "aaatbbscctddt";
 
string []strArray = str.Split(new String[]{"t",StringSplitOptions.RemoveEmptyEntries});
//去除空元素(result :"aaa" "bbscc" "dd")
 
string []strArray = str.Split(new String[]{"t",StringSplitOptions.None});
//保留空元素(result :"aaa" "bbscc" "dd" “”) 
 
方法五:String.Split(Char[],Int32,StringSplitOptions)
 
string str = "aaatbbscctddt";
 
string []strArray = str.Split(new char[]{'t',2,StringSplitOptions.RemoveEmptyEntries});
//切割成2份且去除空元素(result :"aaa" "bbscctddt")
 
string []strArray = str.Split(new char[]{'t',2,StringSplitOptions.None});
//切割成2份且保留空元素(result :"aaa" "bbscctddt" “”)
 
方法六:.String.Split(String[],Int32,StringSplitOptions)
 
string str = "aaatbbscctddt";
 
string []strArray = str.Split(new String[]{"t",2,StringSplitOptions.RemoveEmptyEntries});
//切割成2份且去除空元素(result :"aaa" "bbscctddt")
 
string []strArray = str.Split(new String[]{"t",2,StringSplitOptions.None});//
切割成2份且保留空元素(result :"aaa" "bbscctddt" “”)
 

7f3962b1e40e483583e4865073e17166.png

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _车票系统
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "火车票管理系统";
            string[,] zuo = new string[3, 4];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    zuo[i, j] = (i+1)+"_"+(j+1)+"有票 ";
                }
            }
            string s = string.Empty;
            while (true)
            {
                System.Console.Clear();
                Console.WriteLine("\n       火车票管理系统     " + "\n");
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        System.Console.Write(zuo[i, j]);
                    }
                    System.Console.WriteLine();
                }
                System.Console.Write("请输入座位行号和列号(如:0,2)输入q退出:");
                s = System.Console.ReadLine();
                if (s == "q") break;
                string[] ss = s.Split(',');
                int one = int.Parse(ss[0]);
                int two = int.Parse(ss[1]);
                one -= 1;
                two -= 1;
                if (one <= 3 && two <= 4)
                {
                    if (zuo[one, two] != (one+1) + "_" + (two+1) + "无票 ")
                    {
                        zuo[one, two] = (one+1)+"_"+(two+1)+"无票 ";
                        System.Console.Write("购票成功,按回车键继续购票!");
                        s = System.Console.ReadLine();
                    }
                    else
                    {
                        System.Console.Write("购票失败,请按回车返回重新购票!");
                        s = System.Console.ReadLine();
                    }
                }
                else
                {
                    System.Console.Write("购票失败,请按回车返回重新购票!");
                    s = System.Console.ReadLine();
                }
            }
        }
    }
}

 output:

---



       火车票管理系统



1_1有票 1_2有票 1_3有票 1_4有票

2_1有票 2_2有票 2_3有票 2_4有票

3_1有票 3_2有票 3_3有票 3_4有票

请输入座位行号和列号(如:0,2)输入q退出:1,3

购票成功,按回车键继续购票!



       火车票管理系统



1_1有票 1_2有票 1_3无票 1_4有票

2_1有票 2_2有票 2_3有票 2_4有票

3_1有票 3_2有票 3_3有票 3_4有票

请输入座位行号和列号(如:0,2)输入q退出:2,3

购票成功,按回车键继续购票!





       火车票管理系统



1_1有票 1_2有票 1_3无票 1_4有票

2_1有票 2_2有票 2_3无票 2_4有票

3_1有票 3_2有票 3_3有票 3_4有票

请输入座位行号和列号(如:0,2)输入q退出:q

C:\Users\Administrator\source\repos\ConsoleApp2\bin\Debug\netcoreapp3.1\ConsoleApp2.exe (进程 10736)已退出,代码为 0。

d6ef5f0b8fdd49c099786ec134e3abf2.png


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T1_2
{
    class Program
    {
        static void PrintArray2d(char[,] a2d)
        {
            for(int i = 0;i< a2d.GetLength(0); i++)
            {
                for(int j = 0;j < a2d.GetLength(1); j++)
                {
                    Console.Write(a2d[i, j]);
                }
            }
        }
        static void Main(string[] args)
        {
            string s = ""
               + "#################\n"
               + "#               #\n"
               + "#    ~~~     H  #\n"
               + "#      ~~~      #\n"
               + "#        ~~~    #\n"
               + "#    C    ~~~   #\n"
               + "#     D  C  ~~~ #\n"
               + "#               #\n"
               + "#               #\n"
               + "#################\n";

            Console.Write(s);

            char c = s[0];   // c == '#'

            char[,] map = new char[10, 18];

            for (int i = 0; i < map.GetLength(0); i++)
            {
                for(int j = 0;j < map.GetLength(1); j++)
                {
                    map[i, j] = s[i * 18 + j];
                }
            }

            map[1, 1] = 'o';
            int oi = 1;
            int oj = 1;

            while (true)
            {
                Console.Clear();
                PrintArray2d(map);
                char x = char.Parse(Console.ReadLine());
                switch (x)
                {
                    case 'w':
                        {
                            if (oi > 1)
                            {
                                map[oi, oj] = ' ';
                                oi--;
                                map[oi, oj] = 'o';
                            }
                            break;
                        }
                    case 's':
                        {
                            if (oi <8)
                            {
                                map[oi, oj] = ' ';
                                oi++;
                                map[oi, oj] = 'o';
                            }
                            break;
                        }
                    case 'a':
                        {
                            if (oj > 1)
                            {
                                map[oi, oj] = ' ';
                                oj--;
                                map[oi, oj] = 'o';
                            }
                            break;
                        }
                    case 'd':
                        {
                            if (oi < 10)
                            {
                                map[oi, oj] = ' ';
                                oj++;
                                map[oi, oj] = 'o';
                            }
                            break;
                        }
                }
            }            
        }
    }
}

 

 

 

 

 

 

 

 

具体要求:***********尽量做的简单化 别用CSS技术以及自定义控件 别用脚本语言 我们看不懂 达到我们学生初级初级水平****** 在线售票系统(毕业设计) 系统设置:密码修改 增加用户(权限) [打印机设置 票样打印设置 这2块用不着实现系统界面上 放着就好了] 基础设置:基础参数设置(票设置/订票设置/退票设置)(比如多少时间之前不能票订票) 车票设置(标准票/儿童票/。。。增删改) 车辆设置(增删该) 车次设置(增删该) 运营计划设置(调度设置) 前台营业:销售车票 预定车票 退回车票 信息查询:售票信息查询 订票信息查询 运营计划查询 当班信息查询(类似当班收入什么的) 营业统计:日售票报表统计 月售票报表统计 季度售票报表统计 常用工具:记事本、计算器 备注信息:只要程序 不要论文 5/1号要 你看能不 能按照这个界面这样做 这样应该做界面的人有个参照就简单点吧 最好按照这个系统的流程做 有些具体的我订单上没有写说明的就省了吧 但是你要把刚刚我们2个的都做简单再简单。。。。行不 别用java脚本 或者CSS 不然我们不懂的 界面漂亮点 代码菜鸟点 使用帮助: 1. 把DB文件夹的主数据库webSealTicket_Data.MDF 还原到你的sql 2000数据库系统中 名称不要变为webSealTicket。 2. App_Code文件夹下是sql静态链接类System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("server=(local);database=webSealTicket;uid=sa;pwd=;"); 如直接还原这里不用变化"server=(local)是你的本机的ip地址,database=webSealTicket 是你的数据库名称不要变化,uid=sa 是sql2000的用户名,pwd位密码。 3. login.aspx文件设置成主页,为登录界面。登录成共进入Index.aspx页面。 4. image 文件夹为系统中用到的图片。 5. 如出现连接数据库问题请查看Web.Config文件用记事本打开配置节 为程序中用到的数据库链接。name="webSealTicketConnectionString"为连接字符串。connectionString="Data Source=.;Initial Catalog=webSealTicket; 为数据源。 Security=True"启用安全。 @更多@ http://cleopard.download.csdn.net/ 福利 http://xuemeilaile.com @更多@ http://download.csdn.net/user/cleopard/album 17份软件测试文档 http://download.csdn.net/album/detail/1425 13份WPF经典开发教程 http://download.csdn.net/album/detail/1115 C#资料合辑二[C#桌面编程入门篇] http://download.csdn.net/album/detail/957 C#资料合辑一[C#入门篇] http://download.csdn.net/album/detail/669 [Csharp高级编程(第6版)](共8压缩卷) http://download.csdn.net/album/detail/667 10个[精品资源]Java学习资料合辑[一] http://download.csdn.net/album/detail/663 10个C#Socket编程代码示例 http://download.csdn.net/album/detail/631 6份GDI+程序设计资源整
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值