Chr(13)

[quote=396917:@Martin Fitzgibbons]I load the text file as below

Dim fdict As FolderItem
Dim a As String

If dictbuild = False then
dictbuild = True
App.MouseCursor=System.Cursors.Wait
fdict = GetFolderItem(“Default Dictionary.txt”)
if fdict.Exists then
myDictionary = new ADictionary(fdict)
end if
End if[/quote]
And what code is in ADictionary.Constructor ?

You certainly use a TextInputStream

So, you can set the Encodings there.

Oh darn. When you said dictionary, I thought you meant a Dictionary object, not just a list of words. Ok yeah, we need to see the code that actually does the reading of that file. I’m expecting something that uses a TextInputStream.

Kiama, Australia: a city with the feet into the ocean ! Nice.

If Martin use the example, he may have:

t.Encoding = Encodings.MacRoman

instead of UTF8.

Correct on the first assumption ADictionary is a dictionary Class someone sent back in 2009. The constructor input is below

// This method assumes file format of key space : space defintion CR
// with the first line of the file being the count of items in the file
Dim l,m,n,o,p As Integer
Dim s1 As BinaryStream
Dim temp1,myKey,myValue As String
Dim whichBin,holdBin as Integer
Dim theCount As Integer

if fileToUse.Exists then
ourDict = New Dictionary
DictionaryChanged = false
NeedsSorted = false //assumes input is sorted
s1 = fileToUse.OpenAsBinaryFile(True)
p = s1.Length
temp1 = s1.read§
s1.close
m = 1
// get number of items in dictionary file
l = InStrb(m,temp1,chr(13))
theCount =val(Midb(temp1,m,(l-1)))
Redim wordList(theCount - 1)
theCount = 0 // set back to 0
m=l+1
// load the dictionary
do
l = InStrB(m,temp1,":")
if l = 0 then
exit
end if
myKey = MidB(temp1,m,(l-1-m)) // strip trailing blank and :
myKey = Uppercase(myKey) // store as uppercase
n = InStrB(l,temp1,chr(13))
if n = 0 then
n = p // last item to process
end if
myValue = MidB(temp1,l+2,n-2-l) // strip leading blank
m = n + 1
if ourDict.HasKey(myKey) = False then // use only first one, if duplicates
ourDict.Value(myKey) = myValue // add to Dictionary
o = ourDict.Count - 1
//wordList.Append ourDict.Key(o)
wordList(theCount) = ourDict.Key(o)
theCount = theCount + 1
// update bins
whichBin = ascB(midB(myKey,1,1)) - 64 //index a=1
wordIndex(whichBin) = wordIndex(whichBin) + 1
end if
loop until n = p
// finalize bins
for l = 0 to 25
holdBin = holdBin + wordIndex(l + 1)
wordIndex(l+1) = holdBin
next

else
raise new NilObjectException
end if
Exception
Raise new NilObjectException

When I check what is going into ‘temp1’ as the text file is loading into the Dictionary you see all the CR in the text file are converted to the diamond ? character.

Is the dictionary changing encodings somehow as the crossword program loading works fine elsewhere that I load text files in? I wrote it pre 2003 so not sure if that has any bearings on changes I haven’t update

So just after s1.close, add the following code

Temp1 = DefineEncoding(temp1, Encodings.UTF8) temp1 = ReplaceLineEndings(temp1, endofline)

You should always set the encoding of text that you get from an outside source, whether it be a text file or a database.

The ReplaceLineEndings call will set the line endings to whatever is appropriate for the platform your code is running on.

you can also read carefully given advices…

Not sure what that means Emile but thank you and to Greg that did the trick.
As you can tell I am very casual programmer these days so mastery is mostly gone and I have a lot of trouble remembering how I even wrote my own programs all those years ago. I am extremely thankful for XOJO and the community that helps me with the little challenges I set myself. When you all eventually slow down you will know what I mean … Crossword Wizard lives on in many schools still today :slight_smile:

Martin:
read my answers far above: I talked about DefineEncoding and ReplaceLineEnding. The case appears because strings with different encoding (or no encoding at all: BinaryStream used to read strings).

Note: sometimes, I have troubles reading (like you) / understanding the advice(s) 'till I understand what to do.

No pun intended, just another advice.