PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 24 → WX - Classe Auxiliar para trabalhar com Strings
WX - Classe Auxiliar para trabalhar com Strings
Iniciado por BOLLER ADRIANO, ago., 04 2016 8:54 PM - 2 respostas
Membro registado
2.962 mensagems
Popularité : +89 (91 votes)
Publicado em agosto, 04 2016 - 8:54 PM
Prezados,

Esta classe contém recursos adicionais de manipulação de STRINGS que não são fornecidos por funções WL.

Por favor, sinta-se livre para estender ou otimizar esta classe e republicá-lo no site de recursos.

Os métodos incluíram:

- PadLeft(LOCAL InputString is string, PadCharacter is character, TargetLength is int)

- PadRight(LOCAL InputString is string, PadCharacter is character, TargetLength is int)

- ContainsAlphaOnly(LOCAL InputString is string)

- ContainsDigitsOnly(LOCAL InputString is string)

- ContainsDigits(LOCAL InputString is string)

- ContainsVowels(LOCAL InputString is string)

- StripDoubleSpaces(LOCAL InputString is string)

- StripSpaces(LOCAL InputString is string)

- StripCharsFromList(LOCAL InputString is string, ContinuousCharacterList is string, CaseSensitive is boolean = False)

- StripNonAlphaNumeric(LOCAL InputString is string,StripSpacesAlso is boolean = False)

- StripStringsFromList(LOCAL InputString is string, TABSeperatedStringList is string, CaseSensitive is boolean = False, CompleteWord is boolean = False)

- TrimNonAlphaNumeric(LOCAL InputString is string,TrimSpacesAlso is boolean = True)

- TrimCRLF(LOCAL InputString is string)

- TrimCharsFromList(LOCAL InputString is string, ContinuousCharacterList is string)

- SortSentence(LOCAL InputString is string, StripNonAlphaNumeric is boolean = False)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Mensagem modificada, agosto, 04 2016 - 8:57 PM
Membro registado
2.962 mensagems
Popularité : +89 (91 votes)
Publicado em agosto, 04 2016 - 9:04 PM
Definições da Classe


objString est une Classe

FIN



Procedure Constructeur()



Procedure Destructeur()



FUNCTION PadLeft(LOCAL InputString is string, PadCharacter is character, TargetLength is int)

//Do logic
IF TargetLength > Length(InputString) THEN
//Do logic
InputString = RepeatString(PadCharacter,TargetLength-Length(InputString)) + InputString
ELSE
//Set same value
InputString = InputString
END

//Return padded string

RESULT InputString



FUNCTION PadRight(LOCAL InputString is string, PadCharacter is character, TargetLength is int)

//Do logic
InputString = Complete(InputString,TargetLength,PadCharacter)

//Return padded string
RESULT InputString



FUNCTION ContainsAlphaOnly(LOCAL InputString is string)

//Local variables
Counter is int

//Reformat string to upper
InputString = NoSpace(Upper(NoAccent(InputString)))

//Loop through string
FOR Counter = 1 _TO_ Length(InputString)
IF NOT "A" <= Middle(InputString,Counter,1) <= "Z" THEN
RESULT False
END
END

//Result false
RESULT True



FUNCTION ContainsDigitsOnly(LOCAL InputString is string)

//Local variables
Counter is int

//Reformat string to upper without spaces
InputString = Upper(NoAccent(Replace(InputString," ","",IgnoreCase)))

//Loop through string
FOR Counter = 1 _TO_ Length(InputString)
IF NOT "0" <= Middle(InputString,Counter,1) <= "9" THEN
RESULT False
END
END

//Result false
RESULT True



FUNCTION ContainsDigits(LOCAL InputString is string)

IF StringCount(InputString,"0") > 0 RESULT True
IF StringCount(InputString,"1") > 0 RESULT True
IF StringCount(InputString,"2") > 0 RESULT True
IF StringCount(InputString,"3") > 0 RESULT True
IF StringCount(InputString,"4") > 0 RESULT True
IF StringCount(InputString,"5") > 0 RESULT True
IF StringCount(InputString,"6") > 0 RESULT True
IF StringCount(InputString,"7") > 0 RESULT True
IF StringCount(InputString,"8") > 0 RESULT True
IF StringCount(InputString,"9") > 0 RESULT True
RESULT False




FUNCTION ContainsVowels(LOCAL InputString is string)

InputString = Upper(NoAccent(InputString))
IF StringCount(InputString,"A") > 0 RESULT True
IF StringCount(InputString,"E") > 0 RESULT True
IF StringCount(InputString,"I") > 0 RESULT True
IF StringCount(InputString,"O") > 0 RESULT True
IF StringCount(InputString,"U") > 0 RESULT True
IF StringCount(InputString,"Y") > 0 RESULT True
RESULT False



FUNCTION StripDoubleSpaces(LOCAL InputString is string)

//Replace any double spaces since space is the substring seperator
WHILE StringCount(InputString," ") > 0
InputString = Replace(InputString," "," ",IgnoreCase)
END
//Result reformatted string
RESULT InputString



FUNCTION StripSpaces(LOCAL InputString is string)

//Replace any double spaces since space is the substring seperator
WHILE StringCount(InputString," ") > 0
InputString = Replace(InputString," ","",IgnoreCase)
END
//Result reformatted string
RESULT InputString



FUNCTION StripCharsFromList(LOCAL InputString is string, ContinuousCharacterList is string, CaseSensitive is boolean = False)

//Local variables
lint_Counter is int

//Do cleaning logic
IF NOT NoSpace(ContinuousCharacterList) = "" THEN
FOR lint_Counter = 1 _TO_ Length(ContinuousCharacterList)
IF CaseSensitive THEN
InputString = Replace(InputString,ContinuousCharacterList[[lint_Counter]],"")
ELSE
InputString = Replace(InputString,ContinuousCharacterList[[lint_Counter]],"",IgnoreCase)
END
END
END

//Result cleaned string
RESULT InputString



FUNCTION StripNonAlphaNumeric(LOCAL InputString is string,StripSpacesAlso is boolean = False)

lchar_EvaluateChar is character
lstr_TargetString is string
lint_Counter is int = Length(InputString)

//Leading character
FOR iCounter = 1 _TO_ Length(InputString)
lchar_EvaluateChar = Upper(NoAccent(Middle(InputString,iCounter,1)))
IF "0" <= lchar_EvaluateChar <= "9" OR "A" <= lchar_EvaluateChar <= "Z"
lstr_TargetString += Middle(InputString,iCounter,1)
ELSE
IF lchar_EvaluateChar = " " _AND_ NOT StripSpacesAlso THEN
lstr_TargetString += Middle(InputString,iCounter,1)
END
END
END

//Return reformatted string
RESULT lstr_TargetString



FUNCTION StripStringsFromList(LOCAL InputString is string, TABSeperatedStringList is string, CaseSensitive is boolean = False, CompleteWord is boolean = False)

//Local variables
lint_Counter is int = 0
lstr_StringToStrip is string

//Do cleaning logic
IF NOT NoSpace(TABSeperatedStringList) = "" THEN
FOR ALL STRING lstr_StringToStrip OF TABSeperatedStringList SEPARATED by TAB
IF CaseSensitive THEN
IF CompleteWord THEN
InputString = Replace(InputString,lstr_StringToStrip,"",WholeWord)
ELSE
InputString = Replace(InputString,lstr_StringToStrip,"")
END
ELSE
IF CompleteWord THEN
InputString = Replace(InputString,lstr_StringToStrip,"",IgnoreCase+WholeWord)
ELSE
InputString = Replace(InputString,lstr_StringToStrip,"",IgnoreCase)
END
END
END
//Remove possible created double spaces
InputString = :StripDoubleSpaces(InputString)
END

//Result cleaned string
RESULT InputString



FUNCTION TrimNonAlphaNumeric(LOCAL InputString is string,TrimSpacesAlso is boolean = True)

IF TrimSpacesAlso THEN
//Leading character
WHILE NOT "0" <= Upper(NoAccent(Left(InputString,1))) <= "9" AND NOT "A" <= Upper(NoAccent(Left(InputString,1))) <= "Z"
InputString = Middle(InputString,2)
IF Length(InputString) = 0 THEN
BREAK
END
END

//Trailing character
WHILE NOT "0" <= Upper(NoAccent(Right(InputString,1))) <= "9" AND NOT "A" <= Upper(NoAccent(Right(InputString,1))) <= "Z"
InputString = Middle(InputString,1,Length(InputString)-1)
IF Length(InputString) = 0 THEN
BREAK
END
END
ELSE
//Leading character
WHILE NOT "0" <= Upper(NoAccent(Left(InputString,1))) <= "9" AND NOT "A" <= Upper(NoAccent(Left(InputString,1))) <= "Z" AND Upper(Left(InputString,1)) <> " "
InputString = Middle(InputString,2)
IF Length(InputString) = 0 THEN
BREAK
END
END

//Trailing character
WHILE NOT "0" <= Upper(NoAccent(Right(InputString,1))) <= "9" AND NOT "A" <= Upper(NoAccent(Right(InputString,1))) <= "Z" AND Upper(Left(InputString,1)) <> " "
InputString = Middle(InputString,1,Length(InputString)-1)
IF Length(InputString) = 0 THEN
BREAK
END
END
END

//Return reformatted string
RESULT InputString



FUNCTION TrimCRLF(LOCAL InputString is string)

//Do logic
InputString = NoSpace(InputString)
WHILE Left(InputString,1) IN (CR, CRLF)
InputString = Middle(InputString,2)
IF Length(InputString) = 0 THEN
BREAK
END
END
WHILE Right(InputString,1) IN (CR, CRLF)
InputString = Middle(InputString,1,Length(InputString)-1)
IF Length(InputString) = 0 THEN
BREAK
END
END

//Return padded string
RESULT InputString



FUNCTION SortSentence(LOCAL InputString is string, StripNonAlphaNumeric is boolean = False)

OutputString is string
StringAsArray is array of 0 string

//Clean string
IF StripNonAlphaNumeric THEN
InputString = :StripNonAlphaNumeric(InputString,False)
END
//Remove possible double spaces
InputString = :StripDoubleSpaces(InputString)

//Store string in array
StringToArray(InputString,StringAsArray," ")

//Sort the array
ArraySort(StringAsArray,asAscending)

//Put the array back in a string
OutputString = ArrayToString(StringAsArray," ")

RESULT OutputString



FUNCTION TrimCharsFromList(LOCAL InputString is string, ContinuousCharacterList is string)

//Leading character
WHILE StringCount(ContinuousCharacterList,NoAccent(Left(InputString,1)),IgnoreCase) > 0
InputString = Middle(InputString,2)
IF Length(InputString) = 0 THEN
BREAK
END
END

//Trailing character
WHILE StringCount(ContinuousCharacterList,NoAccent(Right(InputString,1)),IgnoreCase) > 0
InputString = Middle(InputString,1,Length(InputString)-1)
IF Length(InputString) = 0 THEN
BREAK
END
END

//Return reformatted string
RESULT InputString


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membro registado
2.962 mensagems
Popularité : +89 (91 votes)
Publicado em agosto, 04 2016 - 9:05 PM
Download da Classe:

http://depot.pcsoft.fr/resource.awp…

Caso tenha contribuições para melhorar a classe me mande por email ou publique aqui no forum nessa sessão ok.

Muito obrigado ao autor.

:merci:

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/