This is great - how do the strings get saved in the file?

ie. how does it know " acx " = " acromioclavicular "?




QUOTE=minitech;3473993]Ok, here it is, the working code:

vb.net Code:
  1. Public Class Form1
  2.     Structure Abbr
  3.         Dim Abbreviation As String
  4.         Dim Extended As String
  5.     End Structure
  6.     Dim abbrs As List(Of Abbr) = New List(Of Abbr)
  7.     Private Function GetAbbr(ByVal abbrS As String) As Abbr
  8.         Dim rt As Abbr
  9.         Dim cchr As Char
  10.         Dim i As Integer = 0
  11.         rt.Abbreviation = ""
  12.         While i < abbrS.Length
  13.             cchr = abbrS.Chars(i)
  14.             If cchr = " "c Then
  15.                 rt.Extended = abbrS.Substring(i + 1, abbrS.Length)
  16.                 If rt.Abbreviation = "" Then Return Nothing
  17.                 Return rt
  18.             End If
  19.             rt.Abbreviation &= cchr
  20.             i += 1
  21.         End While
  22.         Return Nothing
  23.     End Function
  24.     Private Sub txtMain_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMain.TextChanged
  25.         If Me.txtMain.Text.Chars(Me.txtMain.Text.Length - 1) <> " "c Then Exit Sub
  26.         Dim abbr As Abbr
  27.         For Each abbr In abbrs
  28.             ReplaceAbbr(abbr)
  29.         Next
  30.     End Sub
  31.     Private Sub ReplaceAbbr(ByVal abbr As Abbr)
  32.         Dim original As String = Me.txtMain.Text
  33.         Me.txtMain.Text = Me.txtMain.Text.Replace(abbr.Abbreviation, abbr.Extended)
  34.         If Not (Me.txtMain.Text = original) Then
  35.             Me.txtMain.Select(original.LastIndexOf(abbr.Abbreviation) + (abbr.Extended.Length - abbr.Abbreviation.Length), 0)
  36.         End If
  37.     End Sub
  38.     Private Sub LoadData()
  39.         Try
  40.             Dim fi As New IO.FileInfo("abbr_info.dat")
  41.             If Not fi.Exists Then Throw New IO.FileNotFoundException()
  42.             Dim fs As New IO.FileStream("abbr_info.dat", IO.FileMode.Open, IO.FileAccess.Read)
  43.             Dim rf As New IO.StreamReader(fs)
  44.             While rf.Peek() > -1
  45.                 Dim tmp As Abbr = GetAbbr(rf.ReadLine())
  46.                 If Not Object.Equals(tmp, Nothing) Then
  47.                     abbrs.Add(tmp)
  48.                 End If
  49.             End While
  50.             rf.Close()
  51.             fs.Close()
  52.         Catch ex As Exception
  53.             MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")
  54.         End Try
  55.     End Sub
  56.  
  57.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  58.         LoadData()
  59.     End Sub
  60. End Class
[/QUOTE]