String variable concatenation through loop problem

Hi Team!!
Please can anyone tell me why the following line does not work properly?

str3+=$str2

it seems that str3 variable does not keep its value in order to be concatenated in the next iteration! Thus when i print the result of the line above it returns the str2 value
What i want to do is to add to the existing value of str3 the str2 value (after some trimming).
For example,
if the str2 value has the following values through the iteration

1
0 1
0 0 1
0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

i want in the end the str3 value to be

1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Any help will be appriciated
Panos

declare -i i=0
declare -i len=0
declare -i lenOld=0

#str2=""
#str3=""
cat $2 | while read line2	
do
	echo $line2
	str2=""
	
    for word2 in $line2;
		str2=""
		i=$((0))
		cat $1 | while read line1
		do
			i=$(( i + 1 ))
			#echo $word2 " " $line1
			if [[ $word2 == *"$line1"* ]]
			then
				str2+=" 1"
				i=$((308))
			else
				str2+=" 0"
			fi
		
			if [ "$i" -eq "308" ]
			then
				
				len=${#str2}

				echo $str2
				str3+=$str2
				strTmp=${str3:$lenOld:$len}
				echo $str3 
				lenOld=$len
				break
			fi
		done
		
	done
done

I believe you could use

var=$var" 0"

Thanks for your reply but this will not help me since that what i want to do is "add" the lines of the str2 to form a single line for str3.
My problem is to create a line of 0 and 1 that describe the words found from the comparison of two files.

guess that is also be possible, str3=$str3$str2

I have tried all of them!!! My problem is that when the program returns to for for the next iteration str3 loses its contents!!! ...and equals again to str2

That is probably because for example you are using:

cat $1 | while read line1

causing the while loop to run in a subshell. When the subshell finishes, in most shells this means the variables will be lost.
Instead you could try:

while read line1
do
  ...
done < "$1"

Thanks friend that was the mistake!!
Any idea how from a variable that through an iteration takes the following values

1
0 1
0 0 1
0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

i can end up after the end of the iteration to a variable that has the following form?

1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

One solution that came to my mind was to initialize a string variable with zeros end when ever i have a match to go to the zeros variable and at the ith position to put a 1.

My question is how to go to a specific index into the string and change the value to 1.
Thanks

chr1=${str:0:1}
chr2=${str:1:1}

Thanks for the reply but i cannot understand!!