c# String ,String[] 和 List<String>之间的转换
C#对字符串进行处理时,经常需要进行String,String[]和List<String>之间的转换
本文分析一下它们的差异和转换
一.
1. String > String[]
String s = "ab cd ef gh";
String[] sArray = s.Split(' ');
2. String[] > String
string[] sArray = {"ab", "cd", "ef", "gh"};
string s = String.Join(" ", sArray);
//s = "ab cd ef gh";
3.String[] > List<String>
string[] sArray = { "ab", "cd", "ef", "gh" };
List<String> list = new List<string>(sArray);
4.List<String> > String[]
List<String> list = new List<string>();
list.Add("ab");
list.Add("cd");
list.Add("ef");
list.Add("gh");
string[] sArray = list.ToArray();
5.String和List<String>之间的转换可以使用String[]来中转完成
二.
1. String类型有很多常用的字符串操作成员
字符串是不可变的,虽然这些方法看起来都会改变字符串对象,其实,它们不会改变而是返回了新的
副本。对于一个String,任何“改变”都会分配一个新的恒定字符串。
String s = "ab cd ef gh";
Console.WriteLine("{0}", s.ToUpper());
Console.WriteLine("{0}", s);
/*
返回结果:
AB CD EF GH
ab cd ef gh
*/
2. String[]是定长的,String[]一般是在确定字符串数组的长度的情况下使用
3. List< String >一般在数组的长度会发生变化的情况下使用,例如在数组中间插入一个字符串
c# String ,String[] 和 List<String>之间的转换的更多相关文章
- String、Date、Calendar之间的转换
1.String.Date.Calendar之间的转换 要用到格式化类SimpleDateFormat package com.rong.se; import java.text.ParseExcep ...
- c#-WPF string,color,brush之间的转换
原文:c#-WPF string,color,brush之间的转换 String转换成Color string-"ffffff" Color color = (Color)Colo ...
- String类型和基本数据类型之间的转换
Java 中基本类型和字符串之间的转换 在程序开发中,我们经常需要在基本数据类型和字符串之间进行转换. 其中,基本类型转换为字符串有三种方法: 1. 使用包装类的 toString() 方法 2. 使 ...
- 将String转化成Stream,将Stream转换成String, C# Stream 和 byte[] 之间的转换(文件流的应用)
static void Main( string[] args ) { string str = "Testing 1-2-3"; //convert string 2 strea ...
- char*,string,char a[], const char *,之间的转换
1. const char* 和string 转换 (1) const char*转换为 string,直接赋值即可. EX: const char* tmp = "tsinghu ...
- [java]String和Date、Timestamp之间的转换
一.String与Date(java.util.Date)互转 1.1 String -> Date Date date = DateFormat.parse(String str); St ...
- 【Java】String和Date、Timestamp之间的转换
首先,定义一个Format的日期格式: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 一.S ...
- C#中的Byte,String,Int,Hex之间的转换函数。
/// <summary> Convert a string of hex digits (ex: E4 CA B2) to a byte array. </summary> ...
- String,int,Integer之间的转换
public class Test{ public static void main(String[] args) { //int转换成Integer Integer in = new Integer ...
- String和Date、Timestamp之间的转换
一.String与Date(java.util.Date)互转 1.1 String -> Date String dateStr = "2010/05/04 12:34:23&quo ...
随机推荐
- React Native 之极光推送jpush-react-native 手把手配置
这是 react native 配置极光推送使用的组件,比较常用https://github.com/jpush/jpush-react-native 先把组件地址贴出来,方便大家使用参考.如果这个大 ...
- 字符串、List集合、数组互转
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px "Songti SC"; color: #3933ff } p.p2 { ...
- 回归树(Regression Tree)
目录 回归树 理论解释 算法流程 ID3 和 C4.5 能不能用来回归? 回归树示例 References 说到决策树(Decision tree),我们很自然会想到用其做分类,每个叶子代表有限类别中 ...
- Stackoverflow上有哪些声望高or值得关注的国人
Stackoverflow上有哪些声望高/值得关注的国人? 以下回答并不严格按照 Reputation 排名来列,也不收录不确定是Chinese(中国人或华人)的用户,欢迎补充- 1.李杨 @Li L ...
- [翻译 EF Core in Action 1.11] 何时不应该使用EF Core
Entity Framework Core in Action Entityframework Core in action是 Jon P smith 所著的关于Entityframework Cor ...
- 【我们一起写框架】C#的AOP框架
前言 AOP,大家都是听过的,它是一种面向切面的设计模式. 不过AOP虽然是被称为设计模式,但我们应该很少能看到AOP设计的框架.为什么呢? 因为,AOP单独设计的框架几乎是无法使用的.普遍的情况是, ...
- c# 创建Excel com加载项图片对象批量操作
技术含量较低,主要是通过VBA代码转换成c#代码而来,从而实现图片批量插入.删除.另存为的批量操作,增加文档使用的通用性. 插件主要界面如下: 主要代码如下: private void button8 ...
- 使用redis 中的事务处理实现商品秒杀
redis中的事务处理: redis中的事物事物处理是指能够批量的执行一组命令(当事务开始执行时,事务中的命令能够按照按照规定好的顺序执行而不会被插队或打断): 与mysql事务的区别在于:mysql ...
- ArcGIS API for JavaScript 4.x 本地部署之IIS法
[导读] 关于如何在默认网站(Default Web Site,物理地址C:\inetpub\wwwroot\)启动,已有很多博客详尽地写好了. 本篇在自建网站(本机)中配置http而非https的j ...
- 远程连接身份验证错误,又找不到加密Oracle修正
远程连接服务器出现了错误,错误信息为:远程连接身份验证错误,又找不到加密Oracle修正. 服务器系统:Windows Server2016 客户端系统:Windows10家庭版和专业版 出错原因 ...