Strings are immutable (similar to other languages). There are several
different ways to get what you want, but I tend to utilize IOBuffer a lot:
a = "abcd"
io = IOBuffer()
for char in a
write(io, a + 1)
end
println(takebuf_string(io))
-Jacob
On Wed, Aug 17, 2016 at 12:30 AM, Rishabh Raghunath <[email protected]
> wrote:
>
> Hello fellow Julia Users!!
>
> How do you manipulate the individual characters comprising a string in
> Julia using a for loop ?
> For example:
> ###################
>
> a = "abcd"
>
> for i in length(a)
> a[i]+=1
> end
>
> print(a)
>
> ####################
> I am expecting to get my EXPECTED OUTPUT as " bcde "
>
> BUT I get the following error:
> ##########################################
>
> ERROR: MethodError: `setindex!` has no method matching
> setindex!(::ASCIIString, ::Char, ::Int64)
> [inlined code] from ./none:2
> in anonymous at ./no file:4294967295
>
> ##########################################
> I also tried using:
>
> for i in eachindex(a) instead of the for loop in the above program .. And
> I get the same error..
>
> Please tell me what i should do to get my desired output ..
> Please respond ASAP..
> Thanks..
>