-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2526 from JonAFernan/reto11
Reto#11-c#
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace reto11; | ||
|
||
/* | ||
* Dada una URL con parámetros, crea una función que obtenga sus valores. | ||
* No se pueden usar operaciones del lenguaje que realicen esta tarea directamente. | ||
* | ||
* Ejemplo: En la url https://retosdeprogramacion.com?year=2023&challenge=0 | ||
* los parámetros serían ["2023", "0"] | ||
*/ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
UrlParam("https://retosdeprogramacion.com?year=2023&challenge=0"); | ||
} | ||
|
||
static void UrlParam(string url) | ||
{ | ||
string parameter =""; | ||
List<string> listParameter = new List<string>(); | ||
for (int i = 0; i < url.Length; i++) | ||
{ | ||
if(url[i] == '=') | ||
{ | ||
for (int j = i+1; j < url.Length; j++) | ||
{ | ||
if(url[j] == '&') | ||
{ | ||
i = j; | ||
listParameter.Add(parameter); | ||
parameter=""; | ||
break; | ||
} | ||
parameter += url[j]; | ||
|
||
} | ||
} | ||
} | ||
if(parameter != "")listParameter.Add(parameter); | ||
|
||
if(listParameter.Count == 0) | ||
{ | ||
System.Console.WriteLine("No parameters in the URL"); | ||
return; | ||
} | ||
|
||
if (listParameter.Count == 1) System.Console.Write("The parametes is "); | ||
else System.Console.Write("The parameters are "); | ||
System.Console.Write("["); | ||
|
||
foreach (var item in listParameter) | ||
{ | ||
if(item == listParameter[listParameter.Count-1]) System.Console.Write($"\"{item}\""); | ||
else System.Console.Write($"\"{item}\", "); | ||
} | ||
|
||
System.Console.WriteLine("]"); | ||
} | ||
} |