How can I return the number of the word in text onclick or tap?
I was thinking of using Find.HitHighlight Method (Word) - MSDN(or something similar) but I don't how. For now I can count words in the text I have and store them in collection but how can I now know which one was clicked or taped so it can return me number of that word in collection and highlight it.
Thanks a lot!
here is code for WordCount:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Text.RegularExpressions;
public class WordCount : MonoBehaviour {
public Text textToCount;
// Use this for initialization
void Start () {
Debug.Log(CountWords1(textToCount.text));
}
// Update is called once per frame
void Update () {
}
public static int CountWords1(string s)
{
MatchCollection collection = Regex.Matches(s, @"[\S]+");
return collection.Count;
}
}