在c#中以给定格式反转字符串而不使用内置函数

时间:2016-12-21 13:56:55

标签: c#

问:我有一个字符串"This is paragraph."

所需输出:sihT si hpargarap.

示例代码:

using System.Data;
using System.Text;
class ReverseString
{
  public static void Main()
  {
    string inputString="This is paragraph.";// input can be dynamic
    char[] x=inputString.ToCharArray();
    StringBuilder sb = new StringBuilder();
    for(int i=inputString.Length-1;i>=0;--i)
    {
      sb.Append(x[i]);
    }
    Console.Write(sb.ToString());
    Console.ReadKey();
  }
}

请纠正我。

4 个答案:

答案 0 :(得分:1)

g + guides(color = guide_legend(override.aes = list(size=5)))

答案 1 :(得分:1)

string result = "";
string inputString = "This is paragraph.";
for (int i = inputString.Length - 1; i >= 0; i--)
{
    result += inputString[i];
}
Console.WriteLine(result);
Console.ReadLine();

答案 2 :(得分:1)

不使用C#内置函数即可反转给定字符串

Sub CreateNewSheet()
    Application.ScreenUpdating = False
    Application.Calculation = xlManual

    With Workbooks("Batsmen.xlsx").Worksheets.Add()
    .Name = ThisWorkbook.Worksheets("Summary").Range("E3").Value
    End With

    With ThisWorkbook.Worksheets("Summary").Range("A22:J63").Copy
    Workbooks("Batsmen.xlsx").Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
    Workbooks("Batsmen.xlsx").Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteFormats
    Workbooks("Batsmen.xlsx").Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
    Workbooks("Batsmen.xlsx").Sheets(1).Range("A:J").Font.Size = 10
    End With

    With ThisWorkbook.Worksheets("Summary").Range("A22:J27").Copy
    With Workbooks("Batsmen.xlsx").Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(2)
    .PasteSpecial Paste:=xlPasteValues
    .PasteSpecial Paste:=xlPasteFormats
    .PasteSpecial Paste:=xlPasteColumnWidths
    .Font.Size = 10
    End With
    End With

    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
End Sub

输出:

emocleW

答案 3 :(得分:0)

string outString= string.Join(" ", inString.Split(' ').Select(x=> new string(x.Reverse().ToArray())));