Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Copy text without new line

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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","");;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading