+ 1
(SPOILER)The Spy Life Challenge. Is there a better/cleaner way to do this?
8 odpowiedzi
+ 5
https://www.sololearn.com/learn/9704/?ref=app
+ 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);
}
+ 1
Use Regex to remove other characters than letter
+ 1
I understand what you mean, but i dont know how to write and what does that regex include.
0
Regex?
"Represents an immutable regular expression."
How to use a Regex?
0
s = Regex.Replace(s,@"[^A-Z a-z]","");
Also add namespace
Using System.Text.RegularExpressions;
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);
}
}
}
0
The best way is to create your own Reverse Functions and use RegExp