学习“字符串"在Vbnet中 [英] learning "String" in Vbnet

查看:60
本文介绍了学习“字符串"在Vbnet中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

如何获取"Wavecom调制解调器"从这个值?请给我建议

how to take "Wavecom Modem" from this value ? please give me advice

"AT + CGMI" & vbCrLf& vbCrLf& vbCrLf& " WAVECOM MODEM"; & vbCrLf& vbCrLf& 确定" & vbCrLf

从此结果.我只想使用"Wavecom调制解调器".对我有什么想法吗?

from this result. i only want to take "Wavecom modem". any idea for me?

我使用此代码

Echo = SerialPortABC.ReadExisting
                    Enter1 = Strings.InStr(Echo,vbCrLf)
                    Echo1 = Strings.Right(Echo,(Len(Echo)-Enter1))
                    Enter2 = Strings.InStr(Echo1,vbCrLf)
                    Echo2 = Strings.Right(Echo1,(Len(Echo1)-Enter2-1-))
                    Enter3 = Strings.InStr(Echo2,vbCrLf)
                    Echo3 = Strings.Left(Echo2,(Enter3-1))
                    TextBox2.Text = Echo3

Echo = SerialPortABC.ReadExisting
                    Enter1 = Strings.InStr(Echo, vbCrLf)
                    Echo1 = Strings.Right(Echo, (Len(Echo) - Enter1))
                    Enter2 = Strings.InStr(Echo1, vbCrLf)
                    Echo2 = Strings.Right(Echo1, (Len(Echo1) - Enter2 - 1))
                    Enter3 = Strings.InStr(Echo2, vbCrLf)
                    Echo3 = Strings.Left(Echo2, (Enter3 - 1))
                    TextBox2.Text = Echo3

但结果为零.

感谢您的建议.

推荐答案

如何获取"Wavecom Modem"从这个值?请给我建议

how to take "Wavecom Modem" from this value ? please give me advice

"AT + CGMI" & vbCrLf& vbCrLf& vbCrLf& " WAVECOM MODEM"; & vbCrLf& vbCrLf& 确定" & vbCrLf

从此结果.我只想使用"Wavecom调制解调器".对我有什么想法吗?

from this result. i only want to take "Wavecom modem". any idea for me?

您怎么知道您想参加哪一部分?例如,是否总是第二个非空部分?

How do you know which part you want to take?  Is it always, for example, the second non-empty portion?

Instr会变得很复杂.最好的选择是使用带有Cr或Lf的String.Split作为分割字符,然后检查每个元素的所需匹配项以选择所需的匹配项.删除空条目的选项可能会简化匹配. 我不知道您如何确认该字符串是什么,但是最安全的方法是将Cr或Lf替换为",然后使用另一个分隔符进行拆分.如果拆分失败,请采用另一种方法.

Instr will get complicated.  The best option is to use String.Split with Cr or Lf as the split character, and then examine each element for the required match to select the one you want.  The option to remove empty entries might simplify the matching.   I don't know how you have confirmed what that string is, but the safest approach is to replace Cr or Lf with "", and then split using the other separator.  If the split fails, do it the other way around.  

有关一些示例,请参见:

For some examples, see:



这篇关于学习“字符串"在Vbnet中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆