FUNCTION TrimSpace( cString )
DO WHILE AtNum( " ", cString ) > 0
cString := StrTran( cString, " ", " " )
ENDDO
RETURN cString
carlos vargas wrote:Esta es una función que cambia espacios de mas de uno a uno.
lo uso mucho con instrucciones sql.
- Code: Select all Expand view
FUNCTION TrimSpace( cString )
DO WHILE AtNum( " ", cString ) > 0
cString := StrTran( cString, " ", " " )
ENDDO
RETURN cString
nageswaragunupudi wrote:carlos vargas wrote:Esta es una función que cambia espacios de mas de uno a uno.
lo uso mucho con instrucciones sql.
- Code: Select all Expand view
FUNCTION TrimSpace( cString )
DO WHILE AtNum( " ", cString ) > 0
cString := StrTran( cString, " ", " " )
ENDDO
RETURN cString
For this purpose you may consider using
CHARONE( ' ', cString )
This is a highly optimized function specially meant for removing adjacent duplicate characters.
I know the functions i am talking about are less familiar but the character functions of CT are highly optimized functions.
Full syntax:
CHARONE( [cDelete], cString )
Ex: CharOne( " *-", cStrings ) removes all duplicates of ' ', '*', '-' in one single call.
Elvira said:
Is there a function to remove the intermediate spaces from a string ?
Nages said:
This is a highly optimized function specially meant for removing adjacent duplicate characters.
nageswaragunupudi wrote:But CharRem() function specially made for such purposes and more efficient.
FUNCTION MAIN()
LOCAL cSpaces := SPACE( 100000000 )
LOCAL nSec := SECONDS()
cSpaces = STRTRAN( cSpaces, " ", "" )
? SECONDS() - nSec, LEN( cSpaces )
cSpaces = SPACE( 100000000 )
nSec = SECONDS()
cSpaces = CHARREM( cSpaces, " " )
? SECONDS() - nSec, LEN( cSpaces )
INKEY( 0 )
RETURN NIL
1.36 0
0.00 0
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 19 guests