Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using NHyphenator;
- namespace TestSillabe1
- {
- public partial class MainPage : ContentPage
- {
- private Boolean StIgnore(char lettera)
- {
- char[] daIgnorare = { 'a', 'e', 'i', 'o', 'u', 's' };
- foreach (char c in daIgnorare)
- {
- if (lettera == c) { return false; }
- }
- return true;
- }
- public MainPage()
- {
- InitializeComponent();
- }
- private void Button_Clicked(object sender, EventArgs e)
- {
- Hyphenator hyphenator = new Hyphenator(HyphenatePatternsLanguage.Italian, "-", 1, 1, true);
- string result = hyphenator.HyphenateText(testo1.Text).ToLower();
- int cont = 0;
- if (result.Length > 0) cont = cont + 1;
- for (int i = 0; i < result.Length; i++)
- {
- ///se la stringa è solo una s va in errore, quindi uscire dal for
- if (result.Equals("s"))
- {
- break;
- }
- ///se la stringa è lunga due e il secondo carattere è una s va in errore, quindi uscire dal for
- else if ((result.Length == 2)&&(result[1]=='s'))
- {
- break;
- }
- ///se troviamo la sequenza -s- allora non va considerata come consonante il contatore fa -1 mentre i andrà direttamente dopo -s-
- /*if (((result[i]).Equals('-') == true) && (result[i + 1].Equals('s') == true) && (result[i + 2].Equals('-') == true))
- { //esempio di parole "posto" che viene diviso come po-s-to
- cont = cont - 1;
- i = i + 2;
- }
- non serve è superfluo*/
- ///se troviamo la sequenza s- allora non va considerata come consonante il contatore fa -1 mentre i andrà direttamente dopo s-
- if (result[i].Equals('s'))
- {
- if( i + 2 < result.Length)
- {
- if (result[i + 1].Equals('-') && StIgnore(result[i + 2]))
- {
- cont = cont - 1;
- i = i + 1;
- }
- }
- //esempio di parole "stare" che viene diviso come s-ta-re
- }
- ///quando troviamo un '-' o uno ' ' allora il nostro contatore aumenta di uno
- if (result[i].Equals('-') == true || result[i].Equals(' '))
- {
- cont = cont + 1;
- }
- }
- ///stampa le sillabe
- testo2.Text = result + " \n" + cont;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement