split text syntax

so i have
levelup = split.text (“:”);
level up is Gui text.

i need the text to display the levelup text and display another variable after the " : "

    void experincefull()
    {
        if(GetComponent<Battler>().xpgained >= GetComponent<Battler>().nextlevelxp)
        {
            level += 1;
            GetComponent<Battler>().xpgained = 0;
            GetComponent<Battler>().nextlevelxp *= 3;

            if (level == 1)
            {
                points += 10;
                levelup = split.text (":");
                canspend = true;
                levelup.SetActive(true);
            }
        }
    }

Are you trying to split a string?

What is split?

yes if using a string can accomplish this task

If levelup is a textbox object

string[ ] myStringSplit = myString.split(‘:’);
levelup.text = myStringSplit[0];

This will get the first part of the split string. Not sure how many segments you have or what you are trying to do exactly.

I have it set up like this now but its still not displaying the level variable after the :

    public void onlevelup()

private int level

    {
        canvas.SetActive(true);
        string[] myStringSplit = myString.Split(':');
        levelingup.text = myStringSplit[0] + level;
    }

So, lets look at an example of what is going on in case I’m misunderstanding you.

string myString = "ABC:123";
string[] myStringSplit = myString.Split(':');
levelingup.text = myStringSplit[0];  //levelingup.text will display ABC
levelingup.text = myStringSplit[1];  //levelingup.text will display 123

So this shows the different parts of the array depending on what part you want.
Now, if you are adding level on and level has a value, then you’ll have it added on, but I’d have to see more code to understand what value you should be seeing in your textbox.

so what needs to happen is Level: is displayed in the first part and after : it needs to display the int level inside of the current level text box

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

public class Levelup : MonoBehaviour {
    private int points;
    private int level;
    public GameObject canvas;
    private bool canspend;
    public GameObject Dashstatplus;
    public GameObject Dashstatminus;
    public GameObject Strengthplus;
    public GameObject Strengthminus;
    public GameObject Movementplus;
    public GameObject movementminus;
    public GameObject staminaplus;
    public GameObject staminaminus;
    public GameObject vitalityplus;
    public GameObject vitalityminus;
    public GameObject levelup;
    public Text currentlevel;
    public string mystring;
    // Use this for initialization
    void experincefull()
    {
        if(GetComponent<Battler>().xpgained >= GetComponent<Battler>().nextlevelxp)
        {
            level += 1;
            GetComponent<Battler>().xpgained = 0;
            GetComponent<Battler>().nextlevelxp *= 3;

            if (level == 1)
            {
                points += 10;
                string myString = "Level:";
                string[] myStringSplit = myString.Split(':');
                currentlevel.text = myStringSplit[0] + level ;
                canspend = true;
                levelup.SetActive(true);
            }
        }
    }

Ok, but from what I’m seeing, why do you need to split?

You could just do

currentLevel.text = "Level: " + level;

But that being said, what result are you getting? Does level actually == 1 for the code to run? Are you starting at level 0?

Edit: I think you were splitting because you were taking the old text and splitting off the word Level, but that isn’t really needed if the first part of the text never changes.

thanks a ton works perfectly!