Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to compress space in string?
Message
From
23/05/2003 06:42:48
 
 
To
23/05/2003 04:55:15
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00792083
Message ID:
00792120
Views:
28
Hi Agnes,

I forgot that the routine I posted does not reprocess what has been replaced

What about this, then (no loop)
function do_it()

	local RegExp, x, s
	
	RegExp	= CreateObject('VBScript.RegExp')
	RegExp.IgnoreCase = FALSE
	RegExp.Global = TRUE
	RegExp.Pattern = '\.{2,}'
	
	s = '12.........34.................56.............'
	x = RegExp.Replace(s, '.')
	?'<'+x+'>'
	
	s = '12          34                    56          '
	RegExp.Pattern = ' {2,}'
	x = RegExp.Replace(s, ' ')
	?'<'+x+'>'
	
	&& to remove trailing as well
	s = '12          34                    56          '
	RegExp.Pattern = ' {2,}'
	x = RegExp.Replace(s, ' ')
	RegExp.Pattern = ' $'
	x = RegExp.Replace(x, '')
	?'<'+x+'>'
	

        && or all in one
	local RegExp1, RegExp2
	RegExp1	= CreateObject('VBScript.RegExp')
	RegExp1.IgnoreCase = FALSE
	RegExp1.Global = TRUE
	RegExp1.Pattern = ' {2,}'
	
	RegExp2	= CreateObject('VBScript.RegExp')
	RegExp2.IgnoreCase = FALSE
	RegExp2.Global = TRUE
	RegExp2.Pattern = ' $'
	
	x = RegExp2.Replace(RegExp1.Replace(s, ' '), '')
	?'<'+x+'>'
	
endfunc
>Hi Greg,
>no it does'nt. ::(.
>
>Try a = '12......34...56...'
>Return is 12..34.56. not 12.34.56. as expected.
>
>I know I can do something like
>
>a = '12......34...56...6..5.'
>DO WHILE !EMPTY(OCCURS('..',a))
> a=STRTRAN(a,'..','.')
>ENDDO &&!EMPTY(OCCURS('..',a))
>?a
>
>but I search for something without loop.
>
>Agnes
>
>>Agnes,
>>
>>Does this work ? Replace the dots with spaces
>>
>>
>>
>>a = '12...34...56...'
>>? StringSearchAndReplace(a, '..', '.')
>>
>>*-------------------------------------------------------------------------------
>>function StringSearchAndReplace(Searched, SearchFor, ReplaceWith, IgnoreCase)
>>
>>	local i, Offset, SearchForLength, ReplaceWithLength
>>	
>>	SearchForLength = len(SearchFor)
>>	ReplaceWithLength = len(ReplaceWith)
>>	Offset = 1
>>	
>>	do case
>>	case IgnoreCase
>>		i = atc(SearchFor, substr(Searched, Offset))
>>		do while !empty(i)
>>			i = i + Offset - 1
>>			Searched = stuff(Searched, i, SearchForLength, ReplaceWith)
>>			Offset = Offset + ReplaceWithLength
>>			i = atc(SearchFor, substr(Searched, Offset))
>>		enddo
>>	otherwise
>>		i = at(SearchFor, substr(Searched, Offset))
>>		do while !empty(i)
>>			i = i + Offset - 1
>>			Searched = stuff(Searched, i, SearchForLength, ReplaceWith)
>>			Offset = Offset + ReplaceWithLength
>>			i = at(SearchFor, substr(Searched, Offset))
>>		enddo
>>	endcase
>>	
>>	return Searched
>>endfunc
>>*--------------------------------------------------------------------------
>>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform