私はstring
を取り、その最初の単語を削除し、最後の単語を常に保持する関数を持っています。文字列内の最初の単語を連続して削除し、最後の単語を保持する[Xamarinフォーム] C#
文字列が私の関数SFSpeechRecognitionResult result
から返されます。
私の現在のコードでは、コードが1回実行され、最初の単語が文字列から削除され、最後の単語だけが残されます。しかし、関数が再び実行されると、新しく追加された単語は、result.BestTranscription.FormattedString
string
に積み重なり続けるだけで、最初の単語は削除されません。
これは私の関数である:
RecognitionTask = SpeechRecognizer.GetRecognitionTask
(
LiveSpeechRequest,
(SFSpeechRecognitionResult result, NSError err) =>
{
if (result.BestTranscription.FormattedString.Contains(" "))
{
//and this is where I try to remove the first word and keep the last
string[] values = result.BestTranscription.FormattedString.Split(' ');
var words = values.Skip(1).ToList();
StringBuilder sb = new StringBuilder();
foreach (var word in words)
{
sb.Append(word + " ");
}
string newresult = sb.ToString();
System.Diagnostics.Debug.WriteLine(newresult);
}
else
{
//if the string only has one word then I will run this normally
thetextresult = result.BestTranscription.FormattedString.ToLower();
System.Diagnostics.Debug.WriteLine(thetextresult);
}
}
);
を、したがって、 '.Contains(" ")'は常に真ですか?代わりに 'String.Join(" "、words)'を試してください。 –
なぜ個々の単語の 'List'ではなく、これを文字列として保存しますか?または、おそらく 'Queue 'のように動作しているようです。 –
DavidG
アンも、より高速な方法は、 '文字列newresult = previousresult.Substring(previousresult.IndexOf(」「))になります;' –