I have two text mesh pros and I am trying to copy from one to another. The first text mesh pro looks like this:
Computer.
CPU, GPU, HDD.
Graphics Card Nvidia.
Now I want to copy this to my second text mesh pro but without new lines. That is, the final text should be:
Computer. CPU, GPU, HDD. Graphics Card Nvidia.
How do I do this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class CopyMessage : MonoBehaviour
{
public TextMeshProUGUI text1;
public TextMeshProUGUI text2;
// Start is called before the first frame update
void Start()
{
text2.text = text1.text;
}
>Solution :
Try to replace newlines with blank or whitespace like this:
text2.text = text1.text.Replace("\n","");;