Skip to content

Instantly share code, notes, and snippets.

@fredyfx
Last active May 2, 2018 21:31
Show Gist options
  • Save fredyfx/cec903b0df2f1983cd701aafa6497c9e to your computer and use it in GitHub Desktop.
Save fredyfx/cec903b0df2f1983cd701aafa6497c9e to your computer and use it in GitHub Desktop.
//Accumul.Accum("abcd"); // "A-Bb-Ccc-Dddd". 2 soluciones: una utilizando un string builder y la otra usando Linq
//Accumul.Accum("abcd"); // "A-Bb-Ccc-Dddd"
//Accumul.Accum("RqaEzty"); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
//Accumul.Accum("cwAt"); // "C-Ww-Aaa-Tttt"
public static String Accum(string s)
{
var longitud = s.Length;
Console.WriteLine(longitud);
var arreglo = s.ToCharArray();
StringBuilder sb = new StringBuilder();
for(int i = 0;i<longitud;i++){
int repetir = i+1;
for(int y = 0;y<repetir;y++){
if(y==0){
sb.Append(arreglo[i].ToString().ToUpper());
}else{
sb.Append(arreglo[i].ToString().ToLower());
}
}
if(repetir != longitud)
sb.Append("-");
}
return sb.ToString();
}
public static String Accum2(string s)
{
return string.Join("-",s.Select((x,i)=>char.ToUpper(x)+new string(char.ToLower(x),i)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment