C# List和String互相转换
List转字符串,用逗号隔开
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
list.Add("c");
//MessageBox.Show(list.);
//LoadModel();
string s = string.Join(",", list.ToArray());
MessageBox.Show(s);
List<test> list = new List<test>();
list.Add(new test("1", "a"));
list.Add(new test("2", "b"));
list.Add(new test("", ""));
list.Add(new test("3", "c"));
var a = from o in list select o.test1;
var b = from o in list select o.test2;
string s1 = string.Join(",", a.ToArray());
string s2 = string.Join(",", b.ToArray());
MessageBox.Show(s1 + "\r\n" + s2);
结果:1,2,,3
a,b,,c
字符串转List
这里s的分隔符不是“,”而是“, ”,后面有一个空格
string s = "1, 2, 3";
List<string> list = new List<string>(s.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries));
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
}
这里s的分隔符是“,”
string s = "1,2,3";
List<string> list = new List<string>(s.Split(','));
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
}
C# List和String互相转换的更多相关文章
- C# Byte[] 转String 无损转换
C# Byte[] 转String 无损转换 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// string 转成byte[ ...
- C# 之 将string数组转换到int数组并获取最大最小值
1.string 数组转换到 int 数组 " }; int[] output = Array.ConvertAll<string, int>(input, delegate(s ...
- 转:char*, char[] ,CString, string的转换
转:char*, char[] ,CString, string的转换 (一) 概述 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准 ...
- HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换
1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...
- 【python】bytearray和string之间转换,用在需要处理二进制文件和数据流上
最近在用python搞串口工具,串口的数据流基本读写都要靠bytearray,而我们从pyqt的串口得到的数据都是string格式,那么我们就必须考虑到如何对这两种数据进行转换了,才能正确的对数据收发 ...
- Java - byte[] 和 String互相转换
通过用例学习Java中的byte数组和String互相转换,这种转换可能在很多情况需要,比如IO操作,生成加密hash码等等. 除非觉得必要,否则不要将它们互相转换,他们分别代表了不同的数据,专门服务 ...
- CDuiString和String的转换
很多时候 难免用到CDuiString和string的转换. 我们应该注意到,CDuiString类有个方法: LPCTSTR GetData() const; 可以通过这个方法,把CDuiStrin ...
- [转] HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换
1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...
- c# List< int>和List< string>互相转换
c# List< int>和List< string>互相转换 定义一个list< t> List<int> list = new List<in ...
- 实战c++中的string系列--CDuiString和string的转换(duilib中的cduistring)
使用所duilib的人定会知道cduistring类型,先看看这个类是怎么定义的: class UILIB_API CDuiString { public: enum { MAX_LOCAL_STRI ...
随机推荐
- [转]MySQL5.6新特性之Multi-Range Read
这几天看到mrr的东西,刚好看到以前我们组的一个小伙的博客,我看挺全的,就转过来了,原博客地址请戳 一 介绍 MySQL 5.6版本提供了很多性能优化的特性,其中之一就是 Multi-Range ...
- LeetCode----202. Happy Number(Java)
package isHappy202; /* * Write an algorithm to determine if a number is "happy". A happy n ...
- gfortran、g77等编译器中使用多个文件
gfortran aaaa.f90 bbbb.f90 -o cccc (生成cccc可执行文件,cccc名称可自由设定) 又可以分成两步,因为gfortran先把程序文件编译成*.o文件,再把*.o文 ...
- HttpWebRequest调用WebAPI
private void button1_Click(object sender, EventArgs e) { string ss= HttpPost("http://localhost: ...
- (转)建站知识:域名/ 空间/ IP/ 端口之间的关系
先说域名解析吧,比如说你的域名是 www.sunnymould.com,这个域名对应着一个IP地址,域名解析就是把上面的域名转换成这个IP地址的过程,这样你就可以域名访问了上面地址上的内容了. 端口映 ...
- rmi远程调用
1.在服务器端程序中的spring-servlet.xml中添加 <bean id="userService" class="org.springframework ...
- 十八、AWT绘图技术
1.Graphics 实现各类图形.文本和图片的绘制操作. 2.绘图颜色和笔画属性 (1)颜色属性 Color col= new Color(int r,int g,int b) Color col ...
- What are the advantages of ReLU over sigmoid function in deep neural network?
The state of the art of non-linearity is to use ReLU instead of sigmoid function in deep neural netw ...
- 《BI那点儿事》数据流转换——多播、Union All、合并、合并联接
建立测试数据: CREATE TABLE FactResults ( Name ) , Course ) , Score INT ) INSERT INTO FactResults ( Name , ...
- Hbase之修改表结构
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...