java - Trying to change a string to altcase -


trying write code makes string become altcase (ie. "hello" becomes "hello". borrowed code question on forum asked similar (java case switcher) however, code switched casing of letter instead of having capital letter (first), lowercase letter, etc. pattern.

what have far:

public string altcase(string text) {       string str = "";       (int = 0; <= text.length(); i++)        {         char ca = text.charat(i);          if (text.charat(0).isuppercase)         {             str += character.tolowercase(ca);         }          if (text.charat(0).islowercase)         {             str += character.touppercase;         }          if(i != 0 && character.isuppercase(ca))         {           if (text.charat(i)-1.isuppercase || text.charat(i)+1.isuppercase)           {               str += character.tolowercase(ca);           }            else           {               str += ca;           }         }      if(i != 0 && character.islowercase(ca))         {             if (text.charat(i)-1.islowercase || text.charat(i)+1.islowercase)             {             str += character.touppercase(ca);             }              else             {                 str += ca;             }         }    }       return str;  } 

i'm still relatively new coding in general please excuse inefficiencies, headaches might induce lack of experience in coding. cannot tell going wrong except maybe when typed "text.charat(i)-1.islowercase" statement seems bit illogical, lost in terms of trying come else accomplish same thing. or error elsewhere? in advance.

the modulus operator take long way here...

stringbuilder rslt = new stringbuilder(); (int = 0; < text.length(); i++) {     char c = text.charat(i);     switch (i % 2) {         case 0:             rslt.append(character.touppercase(c));             break;         case 1:             rslt.append(character.tolowercase(c));             break;     } } return rslt.tostring(); 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -