i stuck with this problem,

i could read the text from text-file and index it but i could not update
I’m missing something
defmodule ReadText do
def read_text_file(file_name) do
case File.read(file_name) do
{:ok, text} ->
IO.puts("slice 1: #{String.slice(text, 3..8)}")
slice1 = IO.gets("slice 1 to replace: ")
String.replace(text, String.slice(text, 3..8), slice1, global: false)
IO.puts("slice 2: #{String.slice(text, 72..80)}")
slice2 = IO.gets("slice 2 to replace: ")
String.replace(text, String.slice(text, 72..80), slice2, global: false)
IO.puts("slice 3: #{String.slice(text, 86..91)}")
slice3 = IO.gets("slice 3 to replace: ")
String.replace(text, String.slice(text, 86..91), slice3, global: false)
IO.puts("slice 4: #{String.slice(text, 101..110)}")
slice4 = IO.gets("slice 4 to replace: ")
String.replace(text, String.slice(text, 101..110), slice4, global: false)
{:error, error} ->
IO.puts(error)
end
end
def get_replaceable_indexs(file_name) do
case File.read(file_name) do
{:ok, text} ->
text
|> String.split("")
|> Enum.with_index(fn v, i -> [i, v] end)
{:error, error} ->
IO.puts(error)
end
end
def open(file_path) do
File.open(file_path, [:read, :write], fn text ->
IO.read(text, :all)
end)
end
end
i tried in livebook to get dynamic index for square brockets and use this index as rang in String.slice(text, 3..8) but i’m missing the logic
i highly appreciate any help
thank you





















