Im trying to seperate each syllable of an english word/name into a list. The code I have is counting the syllables perfectly which I also need, but I cannot figure out how to seperate each syllable from the words given. Im using an input field but for now the example word is my name.
im very new to programming so please keep that in mind.
preferred example output would be something like {"joh", "nat", "hon"}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SyllableSeperator : MonoBehaviour
{
string word = "johnathon";
private void Start()
{
SyllableCount(word);
}
public static int SyllableCount(string word)
{
word = word.ToLower().Trim();
List<string> wordList = new List<string>();
bool lastWasVowel = false;
string vowels = "aeiouy";
int count = 0;
foreach (char c in word)
{
if (vowels.Contains(c))
{
if (!lastWasVowel)
{
count++;
lastWasVowel = true;
}
}
else
{
lastWasVowel = false;
}
}
if((word.EndsWith("e") || (word.EndsWith("es") || word.EndsWith("ed"))) && !word.EndsWith("le"))
{
count--;
}
return count;
}
}
what i have tried just does not work at all so I figured I wouldn't post that code.
Again please keep in mind that I am brand new to Unity and programming in general. Someone may have already asked how to do this but the code was too advanced for me.