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

时间:2015-03-11 17:56:07

标签: java regex

嘿伙计们我试图在<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

1 个答案:

答案 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可能会更好。