dimanche 18 mars 2012
ASP: make the first letter uppercase in a string
Do you like this story?
There are two ASP functions that allow us to change the case of a string: UCase and LCase.
The first change all the string in uppercase:
<%=UCase("string")%>STRING<%=LCase("STRING")%>stringIf we don't know what is the case of a string, because, for example, we get it as a query result, how can we make the string with only the first capital letter?
In order to do so, we need to combine the two aforementioned functions, the Left, Right and the Len functions. Len gives us the length of a string as a result, while Left and Right pick a certain number of characters from a string.
First of all we take the first letter of our text and make it a capital letter:
<%= UCase(Left(string,1))%>The rest of the text is a certain number of characters starting from the right hand side of the text minus the first letter.
The number of characters is:
<%=Len(string)-1%><%=Right(Len(string)-1)%><%=LCase(Right(Len(string)-1))%>The complete snippet is the following:
<%= UCase(Left(string,1)) & LCase(Right(string, Len(string) - 1))%>And that is all.
Happy coding!

This post was written by: Franklin Manuel
Franklin Manuel is a professional blogger, web designer and front end web developer. Follow him on Twitter
Inscription à :
Publier les commentaires (Atom)


0 Responses to “ASP: make the first letter uppercase in a string”
Enregistrer un commentaire