0

I got the Answer how to remove Coma beside the word in for loop

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Test : MonoBehaviour { public InputField inputField; public Button Add1; public Button Add2; GameObject Panel; GameObject PanelText1; GameObject PanelText2; GameObject InputField; //bool Addtext = true; //bool Addtext2 = true; public List<string> words = new List<string>(); public List<string> word = new List<string>(); // Start is called before the first frame update void Start() { Add1 = GameObject.Find("/Canvas/Panel/Add1").GetComponent<Button>(); Add1.onClick.AddListener(InputText1); Add2 = GameObject.Find("/Canvas/Panel/Add2").GetComponent<Button>(); Add2.onClick.AddListener(InputText2); PanelText1 = GameObject.Find("/Canvas/Panel/Text1"); PanelText2 = GameObject.Find("/Canvas/Panel/Text2"); InputField = GameObject.Find("/Canvas/InputField"); } public void InputText1() { Text uiText2 = PanelText1.GetComponent<Text>(); string inputString2 = InputField.GetComponent<InputField>().text; string intermediateString = null; words.Add(inputString2); foreach (string wo in words) { intermediateString = intermediateString + "," + wo; } intermediateString = intermediateString.Substring(1); uiText2.text = intermediateString; /* if (uiText2.text == "") { uiText2.text = inputString2; } else { uiText2.text = uiText2.text + "," + inputString2; } */ //words.Add(InputField.GetComponent<InputField>().text); //InputField.GetComponent<InputField>().text = " "; //PanelText1.GetComponent<Text>().text = " "; //for (int i = 0; i < words.Count; i++) //{ // PanelText1.GetComponent<Text>().text += ("," + words[i]);

25th Feb 2021, 12:07 PM
Mohammad Yahya Azhar
Mohammad Yahya Azhar - avatar
1 Réponse
+ 4
Mohammad Yahya Azhar , please do not put a code like this direct in post area. put the code in playground and link it here. people don't like to give help if they have to do copy and paste to be able to run your try. thanks!
25th Feb 2021, 12:46 PM
Lothar
Lothar - avatar