Skip to content

Commit 19f1a62

Browse files
authored
Merge pull request mouredev#4908 from JoseEsmil04/main
#4 - C#
2 parents 28cedc0 + 4455850 commit 19f1a62

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
namespace _04_CADENAS
2+
{
3+
class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
// Declaracion de Cadenas
8+
string cadena1 = "Hola, soy Jose Esmil y estoy aprendiendo C#";
9+
var cadena2 = "Retos de Programacion!";
10+
11+
// Acceso a caracteres especificos
12+
Console.WriteLine($"Primera Forma (Llaves): { cadena1[0] }");
13+
Console.WriteLine($"Segunda Forma (ElementAt): { cadena2.ElementAt(0) }");
14+
15+
// Longitud de Cadenas
16+
Console.WriteLine($"Longitud (Length): { cadena1.Length }");
17+
Console.WriteLine($"Longitud (Count): { cadena2.Count() }");
18+
19+
// Subcadenas
20+
Console.WriteLine($"Subcadena 1: {cadena1.Substring(6, 15)}");
21+
Console.WriteLine($"Subcadena 2: {cadena2.Substring(9, 13)}");
22+
23+
// Concatenacion
24+
Console.WriteLine($"Concatenacion Concat: { string.Concat(cadena1, cadena2) }");
25+
Console.WriteLine($"Concatenacion +: {cadena2 + cadena1}");
26+
27+
// Repeticion (Metodo new String)
28+
var numeral = cadena1[cadena1.Length - 1];
29+
Console.WriteLine($"Repeticion { new String(numeral, 7) }");
30+
31+
// Recorrido
32+
foreach(var letra in cadena1)
33+
{
34+
Console.Write(letra + " ");
35+
}
36+
37+
// Conversion a Mayusculas y Minusculas
38+
Console.WriteLine($"Mayusculas { cadena1.ToUpper() }");
39+
Console.WriteLine($"Minusculas { cadena2.ToLower() }");
40+
41+
// Reemplazo
42+
var reemplazar1 = cadena1.Replace("soy", "me llamo");
43+
var reemplazar2 = cadena2.Replace("Retos", "Desafios");
44+
Console.WriteLine($"Reemplazo 1: {reemplazar1}");
45+
Console.WriteLine($"Reemplazo 2: {reemplazar2}");
46+
47+
// Division
48+
string[] palabraArr = reemplazar1.Split(' ');
49+
Array.ForEach(palabraArr, (palabra) => Console.WriteLine(palabra));
50+
51+
// Union
52+
string fraseUnida = string.Join('_', palabraArr);
53+
Console.WriteLine($"Frase Unida: {fraseUnida}");
54+
55+
// Interpolacion
56+
string country = "Dominican Republic";
57+
string message = $"Made in {country}";
58+
Console.WriteLine($"Interpolacion: {message}");
59+
60+
// Verificacion (Contains, StartsWith, EndsWith)
61+
Console.WriteLine($"Contains: {country.Contains("Republic")}");
62+
Console.WriteLine($"StartsWith: {country.StartsWith("Republic")}");
63+
Console.WriteLine($"EndsWith: {message.EndsWith("Dominican Republic")}");
64+
65+
// Eliminar Espacios (Trim)
66+
string conEspacios = " C# is cool ";
67+
Console.WriteLine($"Trim: { conEspacios.Trim() }");
68+
Console.WriteLine($"TrimStart: { conEspacios.TrimStart() }");
69+
Console.WriteLine($"TrimEnd: { conEspacios.TrimEnd() }");
70+
71+
72+
// Equals (Equivalente)
73+
Console.WriteLine(country.Equals("Dominican Republic"));
74+
75+
// IsNullOrEmpty
76+
string str = "";
77+
bool isNullOrEmpty = string.IsNullOrEmpty(str);
78+
Console.WriteLine(isNullOrEmpty);
79+
80+
// EJERCICIO EXTRA (COMPROBACIONES)
81+
82+
// Palindromo
83+
Console.WriteLine("Palindromo: " + Check.IsPalindrome("aprendiendo c#", "#c odneidnerpa"));
84+
85+
// Isograma
86+
Console.WriteLine("Isograma: " + Check.IsIsogram("murcielago"));
87+
88+
// Anagrama
89+
Console.WriteLine("Anagrama: " + Check.IsAnagram("roma", "amor"));
90+
91+
}
92+
93+
class Check
94+
{
95+
public static bool IsPalindrome(string word, string word2)
96+
{
97+
return word.Reverse().ToArray().SequenceEqual(word2.ToCharArray());
98+
}
99+
100+
public static bool IsIsogram(string word)
101+
{
102+
var newString = word.ToLower();
103+
HashSet<char> chars = new HashSet<char>();
104+
105+
foreach (char c in newString)
106+
{
107+
if (chars.Contains(c))
108+
{
109+
return false;
110+
}
111+
112+
chars.Add(c);
113+
}
114+
115+
return true;
116+
}
117+
118+
public static bool IsAnagram(string word1, string word2)
119+
{
120+
var arrWord1 = word1.ToCharArray();
121+
var arrWord2 = word2.ToCharArray();
122+
123+
Array.Sort(arrWord1);
124+
Array.Sort(arrWord2);
125+
126+
return arrWord1.SequenceEqual(arrWord2);
127+
}
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)