[HELP] Comparing strings C#

I need to grab the last character of string and compare it (it’s used to animate typing text one by one character and I want it wait longer at the end of the line). I am a bit lost. I spent last few hours figuring out how to get it working and after I thought I found a solution, it keeps responding with false. Any ideas? Everything works great, but nothing compared returns true. Relevant code below.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Linq;

IEnumerator AnimationTextLevi1(string strComplete){
    int i = 0;
    str = "";
    while( i < strComplete.Length ){
        if (i>=1){
            string endOfLine = "\n";
            string letterN = "n";
            Debug.Log (str[i-1]);
            Debug.Log ("What's in there? "+string.Equals (str[i-1], letterN ));
		
            if (string.Equals (str[i-1], endOfLine )) {
                 Debug.Log ("met end of line");
                 //yield return new WaitForSeconds (0.5F);
            }
        }
        str += strComplete[i++];
        text.text = str;
        yield return new WaitForSeconds(0.1F);
     }

Only had a quick glance, but aren’t you iterating the characters one at a time, but then trying to compare it to two characters,e.g. “/n” ?

Why not take a look at C#'s String.EndOfLine method?

Privacy & Terms