句子的反词 [英] Reverse word of full sentence
本文介绍了句子的反词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以相反的格式打印字符串:
输入:我的名字是Archit Patel
输出: Patel Archit是我的名字。
I'并捆绑了以下内容,但显示为 letaP tihcrA si ym c。 >公共静态字符串ReverseString(string s)
{
char [] arr = s.ToCharArray();
Array.Reverse(arr);
返回新字符串(arr);
}
解决方案
您需要将将字符串转换成单词,然后反转而不是反转字符:
text = String.Join(,text.Split( '().Reverse())
在框架3.5中:
text = String.Join(,text.Split('').Reverse()。ToArray())
在框架2.0中:
string []单词= text.Split('');
Array.Reverse(words);
text = String.Join(,words);
I want to print string in reverse format:
Input: My name is Archit Patel
Output: Patel Archit is name My
.
I've tied the following but it displays as letaP tihcrA si eman ym
.
public static string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
解决方案
You would need to split the string into words and the reverse those instead of reversing the characters:
text = String.Join(" ", text.Split(' ').Reverse())
In framework 3.5:
text = String.Join(" ", text.Split(' ').Reverse().ToArray())
In framework 2.0:
string[] words = text.Split(' ');
Array.Reverse(words);
text = String.Join(" ", words);
这篇关于句子的反词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文