0

嗨,我想从服务 url“ http://www.findyourfate.com/rss/yearly-horoscope.asp?sign=Aries ”设置一个文本到三个文本块,这是一个字符串,我只想拆分三个字符串并将文本设置为 text1、text2、text3.idone 的三个文本块设置为什么我要拆分意味着在单个文本块中不显示完整内容,因为这个原因我想分成三个字符串。对于第一个文本块我需要显示什么已经成功完成,我尝试设置文本块的其余部分,但我被卡住了,请帮我解决这个问题。我是这个 Windows 8 开发的初学者,请帮助我。

           try
            {

                XDocument xmlDoc = XDocument.Parse(e.Result);
                var result = xmlDoc.Descendants("channel");
                List<xmlList> _xmList = new List<xmlList>();
                foreach (var item in result)
                {
                    var node = item.Descendants("item");
                    //XDocument xdoc = XDocument.Load(e.Result);
                    foreach (var xElememt in node)
                    {
                        string description = xElememt.Element("description").Value;
                        MessageBox.Show("" + description.Length);

                        string input = description;
                        int pattern = input.IndexOf("CAREER");
                        int pattern1 = input.IndexOf("RELATIONSHIP");
                        int pattern2 = input.IndexOf("FINANCE");
                        string str1 = input.Substring(0,pattern);
                        string str2 = input.Substring(pattern,pattern1);
                        string str3 = input.Substring(pattern2);
                        text1.Text = str1;

                        text2.Text = str2;
                        text3.Text = str3;




                        }
4

2 回答 2

1

您可以使用String.Split 方法split生成string.

参考:C# 用另一个字符串分割一个字符串

于 2015-01-14T13:51:18.227 回答
1

您不需要拆分字符串,也不需要使用三个文本块,您可以使用RichTextBox控件来显示信息。它将显示您的完整描述内容

在 .xaml 页面中使用带有滚动条的波纹管代码

          <ScrollViewer 
              VerticalScrollBarVisibility="Visible" 
              ManipulationMode="Control" 
              Height="400" 
              Margin="0,0,0,-13" >
                <RichTextBox TextAlignment="Justify"
                             IsReadOnly="True"
                             Margin="0,0,0,10">
                    <Paragraph Foreground="#626262"
                               FontSize="17"
                               FontStyle="Normal"
                               FontFamily="Regular"  >
                        <Run x:Name="txtDescription" />
                    </Paragraph>
                </RichTextBox>
        </ScrollViewer>

并将 description 的值设置为 .xaml.cs 文件中的 txtDescription

        txtDescription.Text = xElememt.Element("description").Value;
于 2015-01-15T12:47:29.500 回答