【发布时间】:2018-03-15 09:20:54
【问题描述】:
我正在制作一个项目,但我需要能够将 1 行文本拆分为 2 个字符串。 我该怎么做呢?
using System;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Stinger";
Console.Write("Configuration FIle.... ");
Thread.Sleep(1000);
if (System.IO.File.Exists(@"C:\Stinger\Configuration\config.cfg"))
{
Console.Write("Found");
Thread.Sleep(1000);
Console.WriteLine("\r\n");
Console.WriteLine("--Configuration--");
string[] readText = File.ReadAllLines(@"C:\Stinger\Configuration\config.cfg");
foreach (string s in readText)
{
Console.WriteLine(s);
Thread.Sleep(1000);
}
}
else // Configuration File Else Statement
{
Console.WriteLine("Missing");
Thread.Sleep(4000);
}
}
}
这是我的配置内容
fullscreen 1
我希望能够使“全屏”和“1”成为第 2 行字符串的一部分。 我已经完成了持续的谷歌搜索和阅读有关如何拆分的文章。 但这对我来说没有任何意义。 有什么帮助吗?
【问题讨论】:
-
你试过
string[] splitted = s.Split(" ")吗? -
为什么要连续搜索?一个简单的搜索会给你很多建议use this
-
一个简单的谷歌搜索“c# string split”将揭示一切
标签: c#