(SPOILER)The Spy Life Challenge. Is there a better/cleaner way to do this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

(SPOILER)The Spy Life Challenge. Is there a better/cleaner way to do this?

https://code.sololearn.com/cMzGVrxPIfs6/?ref=app

25th Feb 2020, 10:22 PM
Asterothh
Asterothh - avatar
8 Answers
+ 5
https://www.sololearn.com/learn/9704/?ref=app
26th Feb 2020, 3:58 AM
Kevin ★
+ 2
Hi! I share my code with you. I think it's a bit cleaner ;). https://code.sololearn.com/c9stgqi9Jeme static void Main(string[] args) { string str = Console.ReadLine(); List<char> li = new List<char>(); foreach(char c in str) { if(Char.IsLetter(c) || c == ' ') li.Add(c); } li.Reverse(); string myString = new string(li.ToArray()); Console.WriteLine(myString); }
13th Mar 2020, 1:30 AM
Ambrozja 🇵🇱
Ambrozja 🇵🇱 - avatar
+ 1
Use Regex to remove other characters than letter
25th Feb 2020, 10:52 PM
Shahraiz Kayani
Shahraiz Kayani - avatar
+ 1
I understand what you mean, but i dont know how to write and what does that regex include.
26th Feb 2020, 2:49 AM
Asterothh
Asterothh - avatar
0
Regex? "Represents an immutable regular expression." How to use a Regex?
25th Feb 2020, 11:07 PM
Asterothh
Asterothh - avatar
0
s = Regex.Replace(s,@"[^A-Z a-z]",""); Also add namespace Using System.Text.RegularExpressions;
26th Feb 2020, 1:02 AM
Shahraiz Kayani
Shahraiz Kayani - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace SoloLearn { class Program { static void Main(string[] args) { string s = Console.ReadLine(); s = Regex.Replace(s,@"[^A-Z a-z]",""); Console.Write(Reverse(s)); } public static string Reverse(string s) { char[] charArray = s.ToCharArray(); Array.Reverse(charArray); return new string(charArray); } } }
10th May 2020, 2:54 AM
Epsilon ︻╦̵̵͇̿̿̿̿╤──
Epsilon ︻╦̵̵͇̿̿̿̿╤── - avatar
0
The best way is to create your own Reverse Functions and use RegExp
10th May 2020, 2:54 AM
Epsilon ︻╦̵̵͇̿̿̿̿╤──
Epsilon ︻╦̵̵͇̿̿̿̿╤── - avatar