Answer:
I am writing a Python program. Let me know if you want the program in some other programming language.
def toCamelCase(str):
string = str.supercede("-", " ").replace("_", " ")
string = string.split()
if len(str) == 0:
return str
return string[0] + ''.join(i.capitalize() for i in string[one:])
print(toCamelCase("the-stealth-warrior"))
Explanation:
I will explicate the lawmaking line by line. Outset line is the definition oftoCamelCase() method with str every bit an argument. str is basically a string of characters that is to be converted to camel casing in this method.
cord = str.supercede("-", " ").supersede("_", " ") . This statement ways the underscore or dash in the entire are removed. After removing the dash and underscore in the string (str), the rest of the cord is stored in string variable.
Next the string = string.split()uses split() method that splits or breaks the rest of the cord in cord variable to a list of all words in this variable.
if len(str) == 0 ways if the length of the input string is 0 and then return str every bit it is.
If the length of the str string is not 0 so return cord[0] + ''.join(i.capitalize() for i in string[1:])will execute. Lets take an example of a str to show the working of this argument.
Lets say we have str = "the-stealth-warrior". Now after removal of nuance in by replace() method the value stored in cord variable becomes the stealth warrior. Now the carve up() method splits this string into list of three words the, stealth, warrior.
Next return string[0] + ''.join(i.capitalize() for i in string[i:]) has string[0] which is the discussion. Here bring together() method is used to join all the items or words in the string together.
Now i variable moves through the string from index 1 and onward and keeps capitalizing the showtime character of the listing of every word nowadays in string variable from that alphabetize position to the finish.capitalize() method is used for this purpose.
And then this ways first each first grapheme of each discussion in the string starting from index position 1 to the terminate of the cord is capitalized and then all the items/words in string are joined by join() method. This ways the Southward of stealth and W of warrior are capitalized and joined as StealthWarrior and added to string[0] = the which returns theStealthWarrior in the output.
0 Response to "You Can Apply Several Different Worksheet Themes From Which Tab"
Post a Comment