From c29159670eae5f30e664bdfa6ace956d4f1c1e97 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Thu, 23 May 2013 20:42:31 -0400 Subject: [PATCH] Independant behavior for space separated words vs non-space delimiters (word functions) --- mdl/m_strings.pas | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/mdl/m_strings.pas b/mdl/m_strings.pas index 9c247aa..a489176 100644 --- a/mdl/m_strings.pas +++ b/mdl/m_strings.pas @@ -231,16 +231,29 @@ Begin End; Function strWordCount (Str: String; Ch: Char) : Byte; +Var + Start : Byte; Begin Result := 0; + If Ch = ' ' Then + While Str[1] = Ch Do + Delete (Str, 1, 1); + If Str = '' Then Exit; Result := 1; While Pos(Ch, Str) > 0 Do Begin - Inc (Result); - Delete (Str, Pos(Ch, Str), 1); + Inc (Result); + + Start := Pos(Ch, Str); + + If Ch = ' ' Then Begin + While Str[Start] = Ch Do + Delete (Str, Start, 1); + End Else + Delete (Str, Start, 1); End; End; @@ -281,16 +294,22 @@ Begin Temp := Str; If Ch = ' ' Then - While Pos(Ch, Temp) = 1 Do Delete (Temp, 1, 1); + While Temp[1] = Ch Do + Delete (Temp, 1, 1); While Count < Num Do Begin Start := Pos(Ch, Temp); If Start = 0 Then Exit; - While Temp[Start] = Ch Do Inc (Start); + If Ch = ' ' Then Begin + While Temp[Start] = Ch Do + Inc (Start); - Delete (Temp, 1, Start - 1); + Dec(Start); + End; + + Delete (Temp, 1, Start); Inc (Count); End;