Re: [julia-users] Re: How to Manipulate each character in of a string using a for loop in Julia ?

2016-08-17 Thread Erik Schnetter
Alternatively, convert the string to an array of characters, which is
mutable:

```Julia
a = Vector{Char}("abcd")
for i in 1:length(a)
   a[i] += 1
end
```

-erik


On Wed, Aug 17, 2016 at 3:59 AM, 'Greg Plowman' via julia-users <
julia-users@googlegroups.com> wrote:

> I think Jacob meant:
>
> for char in a
>write(io, char + 1)
> end
>



-- 
Erik Schnetter 
http://www.perimeterinstitute.ca/personal/eschnetter/


[julia-users] Re: How to Manipulate each character in of a string using a for loop in Julia ?

2016-08-17 Thread 'Greg Plowman' via julia-users
I think Jacob meant:

for char in a
   write(io, char + 1)
end


[julia-users] Re: How to Manipulate each character in of a string using a for loop in Julia ?

2016-08-17 Thread Rishabh Raghunath
Hello Jacob !!..
I get this error while trying to run your code:

Error evaluating cyclic.jl
LoadError: MethodError: `+` has no method matching +(::ASCIIString, ::Int64)
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...)
  +(!Matched::Int64, ::Int64)
  +(!Matched::Complex{Bool}, ::Real)
  ...
 [inlined code] from /home/rishabh/CodeVita/ProjectJulia/cyclic.jl:6
 in anonymous at ./no file:4294967295
while loading /home/rishabh/CodeVita/ProjectJulia/cyclic.jl, in expression 
starting on line 5


On Wednesday, August 17, 2016 at 12:00:25 PM UTC+5:30, Rishabh Raghunath 
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..
>