[Gambas-user] trimming extra spaces from within a string.

Brian G brian at westwoodsvcs.com
Mon Nov 9 15:37:26 CET 2020


Use this for example Print RegExp.Replace("t y drows on the very best stuff", " {2,}+", " ") 
include the gb.pcre 

Hope this helps 

Brian G 


From: "Bruce Steers" <bsteers4 at gmail.com> 
To: "Gambas mailing list" <user at lists.gambas-basic.org> 
Sent: Monday, November 9, 2020 6:11:27 AM 
Subject: [Gambas-user] trimming extra spaces from within a string. 

Is there a function like this for cleaning up a string of erroneous spaces .. 

Public Sub InTrim(sVar As String) As String 
Dim sOld, sNew, sChar, sLast As String, iPos As Integer 
sOld = Trim(sVar) 
sNew = "" 
For iPos = 0 To sVar.Len - 1 
sChar = sVar[iPos, 1] 
If IsSpace(sChar) And IsSpace(sLast) Then Continue 
sNew &= sChar 
sLast = sChar 
Next 

Return Trim(sNew) 
End 

That will turn " This has many spaces " 
into "This has many spaces" 

cheers 
BruceS 



----[ http://gambaswiki.org/wiki/doc/netiquette ]---- 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/69222538/attachment.htm>


More information about the User mailing list