Dear friends,
Is there a function to remove the intermediate spaces from a string ?.
Very grateful;).
Dear friends,
Is there a function to remove the intermediate spaces from a string ?.
Very grateful;).
Try STRTRAN(var," ","")
Good luck
Thanks:
function QuitaEspacios( cCadena )
return strtran( cCadena, Space(1), Space(0) )
Also
CharRem( <cDelete>, <cString> ) --> cResult
Examples
CharRem( " ", "One Two Three" ) --> "OneTwoThree"
CharRem( "a", "Banana" ) --> "Bnn"
FUNCTION TrimSpace( cString )
聽 聽DO WHILE AtNum( " 聽", cString ) > 0
聽 聽 聽 cString := StrTran( cString, " 聽", " " )
聽 聽ENDDO
RETURN cStringI vote for Jack's version:
STRTRAN(var," ","")
The simpler, the better.
Carlos Vargas solution is better
carlos vargas wrote:Esta es una funci贸n que cambia espacios de mas de uno a uno.
lo uso mucho con instrucciones sql.
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.
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.
Mr James
Elvira's first posting was for removing all spaces.
StrTran( cString, ' '. '' ) is correct.
But CharRem() function specially made for such purposes and more efficient.
Mr Carlos Vargas' posting was to remove duplicate adjacent spaces. I suggested CharOne() for this instead of the code he was using.
These functions were from the 16-bit Clipper days, included in CA_Tools libaray. At that time, most of these functions were written in Assembly language and highly optimized for speed and size.
Now CT.LIB/HBCT.LIB includes all these functions written mostly in C for (x)Harbour.
Those of us who still have the old Clipper installation on our discs can find the documentation in \clipper\ng. This documentation requirs ng.exe or weg.exe to read.
xharbour.com provided a detailed help file (chm) which contains very good documentation. This is very useful
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 0Wow! ++++1
EMG,
Your computer is fast--2.4 times faster than mine. I get:
3.31
0.03
Either way, charRem() is 100 times faster than strtran().
Thanks Nages.
This is only available with xHarbour though?