如何使用C#获取特定的字符串字符 [英] How to get specific string character using c#

查看:91
本文介绍了如何使用C#获取特定的字符串字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查以下示例

输入

string strSample = Reema Jhone shans Roy

string strSample=Reema Jhone shans Roy 

输出

罗杰·罗伊

您能告诉我如何获取两个文本的第一个起始字符串并获取文本的最后一个字符串吗?

Can you please tell me how to get first starting string of two text and get last string of text?

推荐答案



输入

string strSample = Reema Jhone shans Roy

string strSample=Reema Jhone shans Roy 

输出

罗杰·罗伊

您能告诉我如何获取两个文本的第一个起始字符串并获取文本的最后一个字符串吗?

Can you please tell me how to get first starting string of two text and get last string of text?

您可以采用多种方法来做到这一点,包括:

There are any number of ways you could do that, including:

string strSample = "Reema Jhone shans Roy";
string[] names = strSample.Split();
string output = names[0].Substring(0, 1) + ' '
    + names[1].Substring(0, 1) + ' '
    + names[names.Length - 1];

当然,此代码假定
中至少有三个名称 输入字符串.健壮的代码不应该做出这样的假设.
    
-韦恩

Of course this code assumes there will be at least three names in the
input string. Robust code should not make such assumptions.
    
- Wayne


这篇关于如何使用C#获取特定的字符串字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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