<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
但这有错误
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
答案 0 :(得分:0)
正如错误消息所示,Regex.Matcher
会返回Matcher
类型的对象,但您的变量text
需要String[]
。您需要从匹配器中提取字符串,以便将它们放入text
。
从B4A docs开始,您需要执行以下操作:
Dim Matcher1 As Matcher
Matcher1 = Regex.Matcher("<description>(.*)</description>", reciver.GetString)
Do While Matcher1.Find
ListView1.AddSingleLine(Matcher1.Match)
Loop
但这仍然会匹配<description>
和</description>
。在这种情况下,使用正则表达式不是最佳选择,proper XML parsing library可能会更好。