在字段集合中映射字符串 [英] Mapping a string in a collection of fields

查看:98
本文介绍了在字段集合中映射字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法/lib/解决方案可以将字符串映射到字典中,以便直接访问字符串的部分,我的意思是:

字符串a ="NAME ##### SURNAME #### TEL ###### ADDRESS ###### SSN ######### WHATEVER #####";

var x = map(a);
打印x.Name;
打印x.Surname;
打印x.Address;
...

Is there a way/lib/solution to mapp a string into a dictionary whatever in order to have a direct access to the parts of the string I mean:

string a = "NAME#####SURNAME####TEL#######ADDRESS######SSN#########WHATEVER#####";

var x = map(a);
print x.Name;
print x.Surname;
print x.Address;
...

推荐答案

我将创建一个用于封装它的类-如果需要,可以将其称为地图".
实际上将其分解为组成部分很简单:
I would create a class to encapsulate it - you could call it "Map" if you wanted.
Actually breaking it into it''s constituent parts is simple:
string a = "NAME#####SURNAME####TEL#######ADDRESS######SSN#########WHATEVER#####";
string[] parts = a.Split(new char[] {'#'}, StringSplitOptions.RemoveEmptyEntries);


然后,您可以定义常量以通过每个部件在部件数组中的索引来访问它们.


You can then define constants to access each part by it''s index into the parts array.


这篇关于在字段集合中映射字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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