Your problem has 2 hurdles to jump through. /writeini can't support writing trailing spaces to disk unless you enclose your written string with doublequotes. However $readini won't read the surrounding doublequotes nor will it read any leading/trailing spaces. There is a workaround by reading it into a hashtable, from where you can fetch the value using $hget.

Your 2nd problem is that /var and /set will allow setting trailing spaces only if there's at least 2 of them, unless you use the -p switch. In the example below, it shows that the text file contains a leading and trailing space in the 'data', but $readini can only fetch the 4 characters of 'data' without the leading and trailing spaces. However when loading it into a hashtable using /hload, the hashtable item does have the doublequotes stripped, but it does preserve the leading/trailing spaces. Note that using the -p switch with %a1 has no effect because there is no trailing space fetched from disk, but if you remove the -p when setting %a2, you'll lose that trailing space and the length drops from 6 to 5.

//remove test.ini | writeini -n test.ini section item " data " | echo -a $qt($read(test.ini,nt,2)) length read by readini is $len($readini(test.ini,section,item)) | var -sp %a1 $readini(test.ini,section,item) | hload -im test test.ini section | var -sp %a2 $hget(test,item) | echo -a a1 %a1 $len(%a1) vs a2 %a2 $len(%a2)

Note that if you create a hashtable item containing the doublequotes, the quotes are seen by $hget, and they're written to disk by hsave, but they're stripped by /hload.

If you want to create a hashtable item containing 1 trailing space, you'd need to put it into a &binvar then create the table item using /hadd -b

//var -sp %a $+(data,$chr(32)) | noop $regsubex(foo,$+(data,$chr(32)),,,&var) | echo -a $bvar(&var,1-) | hadd -bm table item &var | echo -a $len($hget(table,item))