简体   繁体   English

在basic4android中的标签之间获取字符串

[英]get string between tag in basic4android

hey guys i tried to get string between <description> my text </description> so wrote this one 嘿,我试图在<description> my text </description>之间获取字符串,所以写了这个

Sub JobDone (job As HttpJob)
ProgressDialogHide
If reciver.Success = True Then
Dim text() As String
text=Regex.Matcher("<description>(.*)</description>",reciver.GetString)
Log(text.Length)
For i=0 To text.Length-1
ListView1.AddSingleLine(text(i))
Next
Else
ToastMessageShow("failed",True)
End If
reciver.Release
End Sub

but this got error 但这有错误

src\b4a\example\main.java:379: error: inconvertible types
_text = (String[])(anywheresoftware.b4a.keywords.Common.Regex.Matcher("<description>(.*)</description>",mostCurrent._reciver._getstring()).getObject());
                  ^
  required: String[]
  found:    Matcher

As the error message says, Regex.Matcher returns an object of type Matcher , but your variable text expects a String[] . 如错误消息所述, Regex.Matcher返回一个Matcher类型的对象,但是您的变量text需要一个String[] You need to extract the strings from the matcher, so you can put them into text . 您需要从匹配器中提取字符串,以便将其放入text

From the B4A docs , you would need to do something like this: B4A文档中 ,您需要执行以下操作:

Dim Matcher1 As Matcher
Matcher1 = Regex.Matcher("<description>(.*)</description>", reciver.GetString)
Do While Matcher1.Find
    ListView1.AddSingleLine(Matcher1.Match)
Loop

This would still match <description> and </description> though. 但是,这仍将与<description></description>匹配。 Using regex is not the best option in this case, a proper XML parsing library would probably be better. 在这种情况下,使用正则表达式不是最好的选择, 适当的XML解析库可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM