Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Reverse words in string
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var text = "Hello world!"; var result = text.ReversWords(); Console.WriteLine(result); } } public static class StringExtension{ public static string Revers(this string text){ var reversedTextBuilder = new StringBuilder(); foreach(char ch in text){ reversedTextBuilder.Insert(0,ch); } return reversedTextBuilder.ToString(); } public static string ReversWords(this string text){ var resultTextBuilder = new StringBuilder(); var word = new StringBuilder(); foreach(var ch in text){ if(Char.IsLetter(ch)){ word.Insert(0, ch); }else{ if(word.ToString().Length > 0){ resultTextBuilder.Append(word.ToString()); word.Clear(); } resultTextBuilder.Append(ch); } } resultTextBuilder.Append(word.ToString()); return resultTextBuilder.ToString(); } } }
run
|
edit
|
history
|
help
0
Ship! Wall
TEST 1
asdfsdgghjghkhj
Lexicon
Test
Pot
30272 Program Ex5 if_else_odd_even
towers of hanoi
sxsadxasxd
фабрика статик