How do I make a specific letter of a string uppercase in Julia?

  • A+
Category:Languages

How do I make a specific letter of a string uppercase, and not changing any of the other letters?

My example:

"this works" -> "this woRks" //Change made to letter 7 "this works" -> "this wOrks" //Change made to letter 6 "this works" -> "This works" //Change made to letter 1 

My system uses characters with a UTF-8 encoding, so it needs to support uppercase for UTF-8 characters and not just ascii.

 


Unoptimized one-liner :)

julia> s = "this is a lowercase string" "this is a lowercase string"  julia> String([i == 4 ? uppercase(c) : c for (i, c) in enumerate(s)]) "thiS is a lowercase string" 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: