Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to strip out trailing blanks/CR/LFs from a stri
Message
From
19/07/2004 11:20:57
 
 
To
19/07/2004 11:09:22
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00925773
Message ID:
00925775
Views:
20
>Hi,
>
>What is the best/fastest way to remove trailing carriage returns/line feeds from a string?
>
>Example:
>
>cString = "This is what I want to keep!"                         + ;
>          Space (10) + Chr (13) + Chr (10) + Chr (13) + Chr (10) + ;
>          Space ( 1) + Chr (13) + Chr (10) + ;
>          Space ( 1)
>
>After execution of the routine, all trailing blanks/CR/LFs should be removed (last 18 characters removed, first 28 characters ketp).
>
>TIA
>
>Fernando

Here's a function I use:
* trims leading spaces, cr/lf, tabs from beginning and end of string
function allTrimMemo
lparameters lcInString

	local 	lcCharsToTrim, ;    && string containing all characters to be trimmed
			lcOutString, ;
			lnLength, ;
			lnTrim
			
	* trim leading & trailing CR,LF,spaces, and tabs
	lcCharsToTrim = chr(13) + chr(10) + ' ' + chr(9)
	
	lcOutString = allTrim(lcInString)
	
	* trim trailing items
	lnLength = len(lcOutString)
	lnTrim = 0
	do while substr(lcOutString,lnLength - lnTrim, 1) $ lcCharsToTrim
		lnTrim = lnTrim + 1
	enddo
	if lnTrim > 0
		lcOutString = substr(lcOutString,1,lnLength - lnTrim)
	endif
	
	* trim leading items
	lnTrim = 0	
	do while substr(lcOutString, lnTrim + 1, 1)	$ lcCharsToTrim
		lnTrim = lnTrim + 1
	enddo
	if lnTrim > 0
		lcOutString = substr(lcOutString,lnTrim+1,lnLength - lnTrim)
	endif
	
	return lcOutString
endproc
Steve Gibson
Previous
Reply
Map
View

Click here to load this message in the networking platform