How to detect if there is a space in Input field C#

Hey,
i’m making a command window where you can enter text and it will do that fuction you have setup in the inspector.

So, here was my question what i want to do is if you type in “/Time 1400” it wil set time to 1400 or what ever number, but here is my problem i have set up that you can say “/Time” but how can i set the number to a new public value that i can send to the day and night cirkel??

waht i tought how can i detect a space and then set that number to a new public int that then can be send to the day and night cirkel.

All help is Appreciated!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CommandWindow : MonoBehaviour {

    public InputField CommandLine;
    public string WritedCommand;
    public string Itemtoaddtest;

    [Space(10)]
    public List<Commands> Command = new List<Commands>();

    GameObject Manager;

    void Awake()
    {
        Manager = GameObject.FindWithTag("Manager");
    }

    public void StartCommand()
    {
        WritedCommand = CommandLine.text;
        CommandLine.text = "";

        for (int i = 0; i < Command.Count; i++)
        {
            if (Command[i].CammandLine == WritedCommand)
            {
                if(Command[i].Function == Functions.AddItem)
                    AddItem();

                if (Command[i].Function == Functions.Night)
                    Manager.GetComponent<DayNightController>().Night();

                if (Command[i].Function == Functions.Day)
                    Manager.GetComponent<DayNightController>().Day();
            }
        }
    }

    public void AddItem()
    {
            ItemSystem itemSystem = Manager.GetComponent<ItemSystem>();
            for (int i = 0; i < itemSystem.itemobjects.Count; i++)
            {
                if (itemSystem.itemobjects[i].Name == Itemtoaddtest)
                {
                    itemSystem.itemobjects[i].Amount++;
                    itemSystem.itemobjects[i].Amount_T.text = itemSystem.itemobjects[i].Amount.ToString();
                }
            }
    }
}

[System.Serializable]
public class Commands
{
    public string Name;
    public string CammandLine;
    public Functions Function;
}
public enum Functions
{
    Teleport,
    AddItem,
    Day,
    Night
}

You can use the Split method to get back an array of all the different elements in the string.

string input = "/Time 1400";
string[] parts = input.Split(' ');
// parts[0] is "/Time"
// parts[1] is "1400"

This approach generally requires a lot of validation. For example, you probably want to force it all to uppercase or lowercase; what if someone types “/time” instead of “/Time”? If you intend to accept multiple commands on a single line, you’ll have to step through that array and make sure every other part is a command and that they’re followed by valid values, and so on.

To convert “1400” to an integer use TryParse:

int val = 0;
if(Int32.TryParse(parts[1], out val))
{
    // success, val is integer value of parts[1]
}
else
{
    // failure, parts[1] wasn't a valid integer
}

other string methods: String Class (System) | Microsoft Learn

Hmm that looks interesting assone i’m home i will check it out!:wink: