字符串与List互转

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 + "*"); }

}

时间: 2024-10-16 15:34:16

字符串与List互转的相关文章

用shell将时间字符串与时间戳互转

date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博文 <shell date 命令详解>http://blog.csdn.net/runming918/article/details/7223520 date +%s   可以得到UNIX的时间戳;用shell将时间字符串与时间戳互转:      date -d "2010-10-18

二进制字符串jpg图片互转

二进制字符串jpg图片互转(格式:FFD8FFE000104A******)如:FFD8FFE000104A46494600010100000100010000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832

[java]字符串全半角互转

<pre name="code" class="java"> /** * <DL> * <DT><B> 功能说明</B></DT> * 字符串全半角互转 * </DL> * @author hailan */ public class SBCChange { // public static void main(String[] args) { // // String QJstr

iOS 字符串和图片互转

for (UIImage *myImg in _imgArray) { NSData *imageData = UIImageJPEGRepresentation(myImg,0.5); NSString *_encodedImageStr = [imageData base64Encoding]; [parameters setObject:_encodedImageStr forKey:[NSString stringWithFormat:@"img[%i]",imgCount]]

字符串与json互转

一.json 转字符串 var str = "1:测试1-1;2:测试1-2;3:测试1-3"; //字符串 var str0 = str.split(';'); //字符串转数组[ "1:测试1-1", "2:测试1-2", "3:测试1-3" ] /*方法一*/ //运用 $.map 跟 JSON.parse('str') 方法实现 var str1_1 = $.map( str0, function(value, ind

iOS 字典与字符串之间的互转

/*! * @brief 把格式化的JSON格式的字符串转换成字典 * @param jsonString JSON格式的字符串 * @return 返回字典 */ - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString == nil) { return nil; } NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8Strin

字符串与数组互转

将string字符串转换为array数组 NSArray  *array = [Str componentsSeparatedByString:@","]; ==反向方法 将array数组转换为string字符串 NSString *tempString = [mutableArray componentsJoinedByString:@","];--分隔符

sql2008 将行转为字符串, 将字符串转为行 互转

--将行转为字符串 select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path('')),1,1,'') -- ============================================= -- Description: 将字符串转为表格 /* 例:select * from [f_split]('spu0987*5//spu0988*5/spu0989*5',

java json字符串和对象互转

/** * Created by admin on 2017/7/26. */ public class NewPost { private String title; private String content; public NewPost(){ } public NewPost(String title,String content){ setTitle(title); setContent(content); } public String getTitle() { return ti

iOS开发--字典(NSDictionary)和JSON字符串(NSString)之间互转

1. 字典转Json字符串 + (NSString*)convertToJSONData:(id)infoDict { NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:infoDict options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated stri