有关C#中的字符串解析的信息 [英] Related to String parsing in C#

查看:79
本文介绍了有关C#中的字符串解析的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)

首先,感谢所有早些帮助我的人.

我有一个小查询.

在我的表单中,我有两个窗格.左侧窗格是树视图,右侧窗格是常用控件的集合,例如文本框,复选框,标签等.

在树状视图的每个节点中导航时,我需要填充表格右侧的控件

我需要用来填充控件的值在treeview节点的标签中.

现在,我将值存储在以"|"或";;"分隔的标签中;

我将使用stringvar.split()创建字符串数组.

我有什么方法可以创建一个例程,以将split()方法创建的单个数组存储到右侧窗格中的控件中.

Hi every body :)

First of all, my thanks to all the people who helped me out earlier.

I have a small query.

In my form I have two panes. The left hand pane is a Treeview and the right hand pane is a collection of common controls such as textboxes, checkboxes, labels etc.

As I navigate through each node of the treeview I need to populate the controls on the right hand side of the form

The values with which I need to populate the controls are in the tags of the treeview nodes.

Now I am going to store values in the tags delimited by a ''|'' or a '';''

I will be using stringvar.split() to create an array of strings.

Is there any way for me to create a routine to store the individual arrays created by the split() method into the controls on the right hand pane.

char[] delimiterChars = { '|' };

string text = "This|is|some|text";
string[] words = text.Split(delimiterChars);

foreach (string s in words)
{
   // Do something
}


我只需要一些有关如何将单个字符串存储到控件中的指导,而不会使代码变得混乱

4年后,我已经重新开始使用C#编程

不胜感激:-D


I just need some guidance on how to store the individual strings into the controls, without the code getting messy

I have restarted programming in C# after 4 years

Would appreciate any help :-D

Have a great Day!

推荐答案

根据我的理解,您应该再考虑一下,是否决定将字符串存储在标签中真的那么好. >
在我的项目中,我确实将完整的对象存储在 TreeNode.Tag [^ ]属性.

这样,您可以将值放在我自己的类的属性中,创建该类的实例并将其分配给Tag属性.

读取时,只需将Tag属性的值转换回原始对象即可.

在我看来,比您的字符串解析想法容易和安全得多:-)
From what I do understand, you should think again, whether your decision to store strings in the tag is really that good.

In my projects, I do store full objects in the TreeNode.Tag[^] property.

This way, you could put the values in properties of my own class, create an instance of this class and asign it to the Tag property.

When reading, simply cast the values of the Tag property back to your original object.

Much easier and safer than your string parsing idea, in my opinion :-)


这篇关于有关C#中的字符串解析的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆