Code: Select all
;-TOP
; Comment : Remove Whitespace (PB Developer Tool)
; Author : mk-soft
; Version : v1.01.0
; Create : 18.02.2020
; -----------------------------------------------
EnableExplicit
Procedure.s RemoveRightWhitespace(Text.s)
Protected s1.s, *pText.character, cnt
*pText = @Text
If Not *pText
ProcedureReturn Text
EndIf
Repeat
If *pText\c = 0
ProcedureReturn Text
EndIf
If *pText\c <> ' '
Break
EndIf
cnt + 1
*pText + SizeOf(character)
ForEver
s1 = Left(Text, cnt) + RTrim(Mid(Text, cnt + 1))
ProcedureReturn s1
EndProcedure
; ----
Procedure ClearWhitespaces(Filename.s, Save=#True)
Protected NewList text.s()
Protected r1, file, len1, len2
file = OpenFile(#PB_Any, Filename)
If file
While Not Eof(file)
AddElement(text())
text() = ReadString(file)
Wend
CloseFile(file)
ForEach text()
len1 = Len(text())
text() = RemoveRightWhitespace(text())
len2 = Len(text())
If len1 <> len2
r1 + 1
Debug "Whitespace Line " + Str(ListIndex(text()) + 1)
EndIf
Next
; Save file
If r1 > 0 And Save
file = CreateFile(#PB_Any, Filename)
If file
ForEach text()
WriteStringN(file, text())
Next
CloseFile(file)
EndIf
EndIf
EndIf
ProcedureReturn r1
EndProcedure
; ----
Define r1, file.s
file.s = OpenFileRequester("PB-File", "", "", 0)
If file
r1 = ClearWhitespaces(file)
Debug "*********************************"
Debug "Count Whitespace Lines " + r1
Debug "*********************************"
EndIf