0

在我的网站中,我有一个脚本,它以以下格式返回从我的广播服务器播放的当前歌曲:“艺术家曲目”,我想做的是将该字符串拆分为 2 个字符串:艺术家和曲目,为了做到这一点,我将脚本包装在服务器标签中,如下所示:

<div id="nowPlaying" runat="server">
<script type="text/javascript" src="http://shoutcast.mixstream.net/js/song/uk3-free:34588"></script>     
</div>

在代码后面我做了这样的事情:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim query() As String = nowPlaying.InnerText.Split("-")
        Dim artist As String = query(0)
        Dim track As String = query(1)
        Response.Write(artist + "<br />" + track)

    End Sub

问题是,由于某种原因,字符串数组总是空的,事实上我根本无法进行任何操作(删除、子字符串、lastIndexOf 等),它似乎总是空的。

但如果我不对字符串进行任何操作,一切都很好,我可以看到这样的字符串:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim query As String = nowPlaying.InnerText
        Response.Write(query)

 End Sub

任何想法为什么?

4

3 回答 3

1

用这个...

Dim request As HttpWebRequest = WebRequest.Create("http://shoutcast.mixstream.net/js/song/uk3-free:34588")
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim sTrim = reader.ReadToEnd()

reader.Close()
sTrim=sTrim.Replace("document.write('","")
sTrim=sTrim.SubString(0,sTrim.length-3)
Dim query() As String = sTrim.Split("-")

这会将 js 文件作为字符串加载,然后删除 document.write 语法,让您只剩下艺术家平铺。

于 2010-10-23T12:05:58.787 回答
0

尝试:

Dim query() As String = nowPlaying.InnerText.Split(New [Char]() {"-"c})
于 2010-10-23T10:18:34.413 回答
0

有点刺,但尝试:

Dim sTrim as String = nowPlaying.InnerText
sTrim=sTrim.Replace("document.write('","")
sTrim=sTrim.SubString(0,sTrim.length-3)
Dim query() As String = sTrim.Split("-")
于 2010-10-23T10:41:36.633 回答