2012-11-15 76 views
0

我正在WP7項目上工作。我有一個名爲「URL」的字段。我只想得到網站地址。我想在XAML代碼中實現這一點。從windows phone中獲取URI的網址

Example : 
URL = http://www.techgig.com/skilltest/ASP-Net 

Expected Result : http://www.techgig.com 

<TextBlock x:Name="website" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding URL}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneAccentBrush}"/> 

是否可以在XAML代碼中執行此操作。

回答

0

你應該考慮在你的代碼背後實現(.cs或.vb)。我建議使用「正則表達式」解析出URL字符串以獲得您想要的結果。正則表達式有很多Bing或Google搜索的例子。在C#

簡單的例子:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Text.RegularExpressions; //needed 

namespace SplitingStrings 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string input = "http://www.yo.com/stuff/you/donot/want"; 
      string pattern = "(.com/)";   // Split on .com/ 

      string[] substrings = Regex.Split(input, pattern); 
      foreach (string match in substrings) 
      { 
       Console.WriteLine("'{0}'", match); 
      } 

      Console.WriteLine(substrings[0] + substrings[1]); //this is what you want 

      Console.ReadKey(true); 
      // The method writes the following to the console: 
      // 'http://www.yo' 
      // '.com/' 
      // 'stuff/you/donot/want' 
      // http://www.yo.com/ 

     } 
    } 
} 

來源:MSDN