First I have to receive a string from the user. The function would be capitalizing the introduced string object. It would make the words start with uppercased characters and all remaining characters have lower case. Here is what I did:
ssplit = s.split()for z in s.split(): if ord(z[0]) < 65 or ord(z[0])>90: l=(chr(ord(z[0])-32)) new = l + ssplit[1:] print(new) else: print(s)
I can't see what I am doing wrong.
How do I make the first letter of a string uppercase, but not change the case of any of the other letters?
For example:
"this is a test"
-> "This is a test"
"the Eiffel Tower"
-> "The Eiffel Tower"
"/index.html"
-> "/index.html"
This question already has an answer here:
I saw this topic here: First lowercase the text then capitalize it. Is it possible with CSS?
But it wasn't pure CSS. I have a div that contains this text:
<div>RaWr rAwR</div>
I want to use css to make it look like "Rawr Rawr". Cut if I just to text-transform capitalize it makes it "RaWr RAwR", the already uppercase letters remain upper case. So I need to lower case it all first then capitalize, is the solution to wrap it in a div?
I tried wrapping it in another div but it didnt work:
<style> #test3 { text-transform: lowercase; } #test3 div { text-transform: capitalize; }</style><div id="test3"><div>RaWr rAwR</div></div>
I am trying to extract the names of Lakes from some text that I have in R. The lakes are proper (capitalized) but will require me extracting a few words on either side of the word "Lake".
I tried a few things but nothing is working quite the way I want it to... in some cases, a sentence or the article may begin with "Lake" so there is no text before it. In some cases, the proper name may be 3 words (Lake St. Clair or Red Hawk Lake).
Example code to work with:
text <- paste("Lake Erie is located on the border of the United States and Canada.", "It is located nearby to Lake St. Clair and Lake Michigan.", "All three lakes have a history of high levels of Phosphorus.", "One lake that has not yet been impacted is Lake Ontario.")
This was maybe the closest I got-- pulling from another stack overflow but it's still not working out.
context <- function(text){splittedText <-strsplit(text,'',T) print(splitted Text) data.frame(before = head(c('',splittedText),-1),words=splittedText,after=tail(c(splittedText,''),-1))}info <- context(text)print(subset(info, words == 'Lake')
I would like to get either: 1) the proper lakes names extracted ("Lake Erie", "Lake St. Clair", etc.) OR 2) a dataframe with the words before and after "Lake". Ideally the first but I'm flexible at this point.
before <- c("","nearby to", "Clair and","impacted is")Lake <- c("Lake","Lake","Lake","Lake")after <- c("Erie is","St. Clair", "Michigan ","Ontario ")output <- data.frame(cbind(before,Lake,after)); print(output)
Thanks in advance for the help!
The default seems to be upper case, but is there really any reason to use upper case for keywords? I started using upper case because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored procedure. But then, I felt terrible for my baby (5th) finger, that always needs to hold down the Shift button, so I stopped using upper case. Any reason why I should go back to upper case?
Edit: Thanks for the answers guys. I wasn't programming yet back in the days when COBOL was king, so I wasn't aware of this. I'll stick with lower case from now on.
Please note that by viewing our site you agree to our use of cookies (see Privacy for details). You will only see this message once.