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:
[/QUOTE]vb.net Code:
Public Class Form1 Structure Abbr Dim Abbreviation As String Dim Extended As String End Structure Dim abbrs As List(Of Abbr) = New List(Of Abbr) Private Function GetAbbr(ByVal abbrS As String) As Abbr Dim rt As Abbr Dim cchr As Char Dim i As Integer = 0 rt.Abbreviation = "" While i < abbrS.Length cchr = abbrS.Chars(i) If cchr = " "c Then rt.Extended = abbrS.Substring(i + 1, abbrS.Length) If rt.Abbreviation = "" Then Return Nothing Return rt End If rt.Abbreviation &= cchr i += 1 End While Return Nothing End Function Private Sub txtMain_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMain.TextChanged If Me.txtMain.Text.Chars(Me.txtMain.Text.Length - 1) <> " "c Then Exit Sub Dim abbr As Abbr For Each abbr In abbrs ReplaceAbbr(abbr) Next End Sub Private Sub ReplaceAbbr(ByVal abbr As Abbr) Dim original As String = Me.txtMain.Text Me.txtMain.Text = Me.txtMain.Text.Replace(abbr.Abbreviation, abbr.Extended) If Not (Me.txtMain.Text = original) Then Me.txtMain.Select(original.LastIndexOf(abbr.Abbreviation) + (abbr.Extended.Length - abbr.Abbreviation.Length), 0) End If End Sub Private Sub LoadData() Try Dim fi As New IO.FileInfo("abbr_info.dat") If Not fi.Exists Then Throw New IO.FileNotFoundException() Dim fs As New IO.FileStream("abbr_info.dat", IO.FileMode.Open, IO.FileAccess.Read) Dim rf As New IO.StreamReader(fs) While rf.Peek() > -1 Dim tmp As Abbr = GetAbbr(rf.ReadLine()) If Not Object.Equals(tmp, Nothing) Then abbrs.Add(tmp) End If End While rf.Close() fs.Close() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!") End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load LoadData() End Sub End Class




Reply With Quote
