我一直在初学者学习单上得到这个问题...... [英] I keep getting this question on beginner study sheets...

查看:71
本文介绍了我一直在初学者学习单上得到这个问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但我似乎无法找到答案。

问题是如何扭转字符串中的单词?

或者你如何扭转字符串中列出的数字?


示例通常类似于:

将此字符串转换为1,2,3,4,... ;

进入...... 4,3,2,1


这个看起来很难,更不用说试图改变一串

空间分隔的单词(甚至是可能的?一个技巧问题

或许?)


再次,这里的任何帮助都非常感谢。

谢谢!


杰夫

But I can''t seem to find the answer.
The question is how do you reverse the words in a string?
Or how do you reverse the numbers listed in a string?

The example is usually something like:
Turn this string "1,2,3,4,..."
Into "...4,3,2,1"

This one seems hard enough let alone trying to turn a string of
space-seperated words around(is that even possible? a trick question
perhaps?)

Again, any help here much appreciated.
Thanks!

Jeff

推荐答案

你好,


这是你想要的东西吗?


使用系统;


命名空间反向

{

///< summary>

/// Class1的摘要说明。

///< / summary>

class Class1

{

///< summary>

///应用程序的主要入口点。

///< / summary>

[STAThread]

static void Main(string [] args)

{

//

// TODO:添加代码以启动应用程序

//

string str =" 1,2,3,4";

string result ="" ;;

for(int i = str.Length - 1; I> = 0;我 - )

{

结果+ = str.Substring(i,1);

}

Console.WriteLine(" Start string:" + str);

Console.WriteLine(" Result string:" + result);

Console.ReadLine( );

}

}

}

希望有所帮助......虽然可能有更简单的方法这样做......


John

" z_learning_tester" <所以***** @ microsoft.com>在消息中写道

news:ej2Bc.71373
Hi,

Is this the kind of thing you are after?

using System;

namespace Reverse
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
string str = "1,2,3,4";
string result = "";
for (int i = str.Length - 1; i>=0; i--)
{
result += str.Substring(i, 1);
}
Console.WriteLine("Start string: " + str);
Console.WriteLine("Result string: " + result);
Console.ReadLine();
}
}
}
Hope that helps... Although there may be easier ways to do it...

John
"z_learning_tester" <so*****@microsoft.com> wrote in message
news:ej2Bc.71373


eu.3683@attbi_s02 ...
eu.3683@attbi_s02...
但我似乎不能找到答案。
问题是你如何扭转字符串中的单词?
或者你如何反转字符串中列出的数字?

这个例子通常是类似于:
将此字符串1,2,3,4,...转换为... 4,3,2,1
这个看起来很难,更不用说试图把一串空间分开的单词转过来(甚至可能吗?一个技巧问题也许?)

再次,任何非常感谢。
谢谢!

杰夫
But I can''t seem to find the answer.
The question is how do you reverse the words in a string?
Or how do you reverse the numbers listed in a string?

The example is usually something like:
Turn this string "1,2,3,4,..."
Into "...4,3,2,1"

This one seems hard enough let alone trying to turn a string of
space-seperated words around(is that even possible? a trick question
perhaps?)

Again, any help here much appreciated.
Thanks!

Jeff



一种方法:


使用String.Split()和逗号作为分隔符,将数字

子串分解为数组。然后从最后遍历数组到

开始,将子串重新组合成你想要的顺序。对于

例如:

HTH,

Tom Dacon

Dacon软件咨询

" z_learning_tester" <所以***** @ microsoft.com>在消息中写道

news:ej2Bc.71373
One approach:

Use String.Split() with a comma as the delimiter, to break up the numeric
substrings into an array. Then iterate over the array from the end to the
beginning, to reassemble the substrings into the order you want. For
example:
HTH,
Tom Dacon
Dacon Software Consulting
"z_learning_tester" <so*****@microsoft.com> wrote in message
news:ej2Bc.71373


这篇关于我一直在初学者学习单上得到这个问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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