How to recognize alphaMeric characters
Posted: Wed Sep 27, 2023 5:11 pm
TIA ,
I am writing a program that will Read a .txt file
collect and store each word into List ;
then Sort the List
(Here , I plan to TRIM List here , once I learn how to recognize alohaMeric characters)
then Write Sorted List to .txt file .
Now I want to LTrim and RTrim anything that is NOT NlphaMeric ,
A-Z , a-z and 0-9 ,
and consider some common symbols such as @, #, *, and & as NOT AlphaMeric .
Below is my code
(please excuse my simpleton code , I write code this way (step by step)
so that years from now I will be able to understand each step .
So , my question is:
How can I recognize Leading and Trailing alphaMeric characters (as defined above) .
I am writing a program that will Read a .txt file
collect and store each word into List ;
then Sort the List
(Here , I plan to TRIM List here , once I learn how to recognize alohaMeric characters)
then Write Sorted List to .txt file .
Now I want to LTrim and RTrim anything that is NOT NlphaMeric ,
A-Z , a-z and 0-9 ,
and consider some common symbols such as @, #, *, and & as NOT AlphaMeric .
Below is my code
(please excuse my simpleton code , I write code this way (step by step)
so that years from now I will be able to understand each step .
So , my question is:
How can I recognize Leading and Trailing alphaMeric characters (as defined above) .
Code: Select all
; Author: Vern Marsden vmars316
; http://www.purebasic.fr/english/
; https://www.purebasic.com/documentation/
; CRLF = +Chr(10)+Chr(34)+
;
; ReadFile_Words_to_List.pb
EnableExplicit
Global FileName$="ReadFile_Words_to_List.txt"
Global NewList WordsList.s() , WordsListCOUNT = 0
; The first list element is at position 0, the next at 1 and so on.
; ============================================================
If ReadFile(0, FileName$)
Global aLine$ , aLineLEN = 0 , BlankPOS = 0 , StartPOS= 1 , LastPOD = 0 ,
StartMid = 0 , BlankPOS = 0 , MidWord$ ,
LastWord$ , LastWordLEN = 0
ClearList(WordsList())
Repeat ; for each line
BlankPOS = 0 : StartPOS= 1
aLine$ = ReadString(0) ; Read Next Line
; Debug aline$
aLineLEN = Len(aLine$)
; parse/collect wordscl
Repeat ; for each word
BlankPOS = FindString(aLine$, " " , StartPOS , #PB_String_NoCase)
If BlankPOS > 0
MidWord$ = Mid(aLine$, StartPOS , BlankPOS - StartPOS + 1 )
AddElement(WordsList())
WordsList() = MidWord$
WordsListCOUNT = WordsListCOUNT + 1
StartPOS = BlankPOS + 1
EndIf
Until BlankPOS < 1 ;
; ============================================================
If BlankPOS < 1 ; There are no more Blanks/Spaces
LastWordLEN = aLineLEN - StartPOS + 1
LastWord$ = Mid(aLine$, StartPOS , LastWordLEN + 1)
AddElement(WordsList())
WordsList() = LastWord$
EndIf
; Debug aline$
Until Eof(0) ; eol
CloseFile(0)
; ============================================================
SortList(WordsList(),#PB_Sort_Ascending | #PB_Sort_NoCase)
MessageRequester("Information", "There are "+Str(ListSize(WordsList()))+" elements in the list", #PB_MessageRequester_Ok)
; ============================================================
; Trim code goes here .
; ============================================================
CreateFile(2, "Words_List_OUT.txt", #PB_UTF8)
ForEach WordsList()
Debug WordsList()
WriteStringN(2, WordsList() , #PB_UTF8) ; "Words_List_OUT.txt"
Next
EndIf
; ============================================================
End