[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RegExp.Replace


hello

if pattern is easy, you can use scan ...

:~$ gbs3 -e 'Dim s As String = "A     B    C D   E": for each item as string in scan(s,"* * * * *"): print item: next'
A
B
C
D
E
:~$ gbs3 -e 'Dim s As String = "A     B    C D   E": dim tab as string[]=scan(s,"* * * * *"): for each item as string in tab: print item: next '
A
B
C
D
E

manu.

Le 02/12/2025 à 14:47, CD a écrit :


No, I found it elegant, efficient,

and it only takes one line of code!

Well done, Olivier!

Regards




Le mardi 02 décembre 2025 à 11:55 +0000, Bruce Steers a écrit :

Sorry GianLuigi I have made a mistake. I just searched the lists for the conversation and it turns out it was Oliver Cruilles that surprised everyone with the simple solution. At this point I think everyone facepalmed ;) https://lists.gambas-basic.org/pipermail/user/2020-November/070587.html

Sorry about that

Respects
BruceS


On Tue, 2 Dec 2025 at 11:36, Gianluigi <gradobag@xxxxxxxxxxx <mailto:gradobag@xxxxxxxxxxx>> wrote:
If you're sure of that, then I'm in worse shape than I thought. LOL

Best Regards
Gianluigi

Il 02/12/25 10:51, Bruce Steers ha scritto:
>
> Use SPlit() with IgnorVoid parameter and Join again.
>
> InText = Split(InText, " \t", Null, True).Join(" ")
>
> This answer was provided by GianLuigi many moons ago as the fastest way
> to make a multi spaced line have only 1 space between chars.
> Ps. i use \t in the Split to catch tab spaces too.
>
> Respects
> BruceS
>
>
> On Tue, 2 Dec 2025 at 09:19, Ian Roper <westozscribe@xxxxxxxxx <mailto:westozscribe@xxxxxxxxx> > <mailto:westozscribe@xxxxxxxxx <mailto:westozscribe@xxxxxxxxx>>> wrote:
>
>     __
>
>     Public Function ClearDuplicateSpaces(InText As String) As String
>
>        While (InStr(InText, "  ") > 0)
>          InText = Replace(InText, "  ", " ")
>        Wend
>        Return InText
>
>     End
>
>
>     On 2/12/25 3:13 pm, CD wrote:
>>     Hello,
>>
>>     I have a string like this:
>>
>>     Dim s As String = "A     B    C D   E"
>>
>>     s = RegExp.Replace(s, "\\s+", " ")
>>
>>     Print s
>>
>>     I would like to get "A B C D E"
>>
>>     What should I write in the Pattern string?
>>     I've tried many things, without success.
>>     So what should I change to get the desired result?
>>
>>     Regards
>>




References:
RegExp.ReplaceCD <dessere.claude@xxxxxx>
Re: RegExp.ReplaceIan Roper <westozscribe@xxxxxxxxx>
Re: RegExp.ReplaceBruce Steers <bsteers4@xxxxxxxxx>
Re: RegExp.ReplaceGianluigi <gradobag@xxxxxxxxxxx>
Re: RegExp.ReplaceBruce Steers <bsteers4@xxxxxxxxx>
Re: RegExp.ReplaceCD <dessere.claude@xxxxxx>