-6

I am making a project, But i need to be able to split 1 row of text into 2 strings. How would i go about doing this?

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);
        }
    }
}

And here is my Config Contents

fullscreen 1

I want to be able to make "fullscreen" and "1" part of the row 2 strings. I've done continuous googling and reading articles on how to split. But it's not making any sense to me. Any help?

Dan Siebles
  • 35
  • 1
  • 4

1 Answers1

0

This is a simple string.Split and is actually very straightforward and fundamental.

Assuming this is the code where you are getting fullscreen 1 from, you can do something like this.

            string[] readText = File.ReadAllLines(@"C:\Stinger\Configuration\config.cfg");
            foreach (string s in readText)
            {
                string[] split= s.Split(" ");
                Console.WriteLine(split[0]+" "+split[1]);
                Thread.Sleep(1000);
            }

The Console.WriteLine will print your expected output.

Bejasc
  • 930
  • 1
  • 8
  • 20