2012-11-15 48 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