StringBuilder buf = new StringBuilder();
for(int t = 0; t < wordarray.length - 1; t++) {
String s = wordarray[t];
if (numberWord.contains(s) && isWordNumber(wordarray[t + 1]) {
s = addCommas(wordarray[t + 1]);
}
buf.append(' ').append(s);
}
Split along spaces and other whitespace, then you can check if each word is a number.
Then you can convert that word into characters, add in commas, then put it back in.
Ideally, if your text-to-speech solution supports it, copy this back into a hidden text field, then use that for the speech, so the user doesn't see the modification.
You may want to just use tryParse though, for simplicity:
After reading the edit to the question, by splitting into words, then start with converting the string to lower-case, so you can easily compare, then, just loop through each word.
StringBuilder buf = new StringBuilder();
for(int t = 0; t < wordarray.length - 1; t++) {
String s = wordarray[t];
if (numberWord.contains(s) && isWordNumber(wordarray[t + 1]) {
s = addCommas(wordarray[t + 1]);
}
buf.append(' ').append(s);
}
发布评论
评论(4)
您是否考虑过简单的 string.Replace?即
对每个数字重复
您还需要编辑文本框吗?在将文本发送到文本到语音实用程序之前,您不能只处理文本(从文本框中获取)吗?
Have you considered a simple string.Replace? i.e.
Repeat for each number
Also do you need to edit the text box, can't you just process the text (taken from the text box) before sending it to the text to speech utility?
沿着空格和其他空格分割,然后您可以检查每个单词是否是数字。
然后,您可以将该单词转换为字符,添加逗号,然后将其放回原处。
理想情况下,如果您的文本转语音解决方案支持它,请将其复制回隐藏文本字段,然后将其用于语音,这样用户看不到修改。
为了简单起见,您可能只想使用 tryParse:
http://msdn.microsoft .com/en-us/library/f02979c7.aspx
其中 value 是
String
。更新
阅读问题的编辑后,通过拆分为单词,然后开始将字符串转换为小写,以便您可以轻松比较,然后循环遍历每个单词。
Split along spaces and other whitespace, then you can check if each word is a number.
Then you can convert that word into characters, add in commas, then put it back in.
Ideally, if your text-to-speech solution supports it, copy this back into a hidden text field, then use that for the speech, so the user doesn't see the modification.
You may want to just use tryParse though, for simplicity:
http://msdn.microsoft.com/en-us/library/f02979c7.aspx
Where value is a
String
.Update
After reading the edit to the question, by splitting into words, then start with converting the string to lower-case, so you can easily compare, then, just loop through each word.
此方法将解析数字并将它们放入逗号分隔的格式:
This method will parse the numbers and put them in comma delimited format:
您需要向文本框添加一个事件(例如 KeyPress)处理程序。
You need to add an event(e.g KeyPress) handler to the text box.