function to supress intermediate spaces
function to supress intermediate spaces
Dear friends,
Is there a function to remove the intermediate spaces from a string ?.
Very grateful;).
Is there a function to remove the intermediate spaces from a string ?.
Very grateful;).
Re: function to supress intermediate spaces
Try STRTRAN(var," ","")
Good luck
Good luck
Re: function to supress intermediate spaces
Thanks:
function QuitaEspacios( cCadena )
return strtran( cCadena, Space(1), Space(0) )
function QuitaEspacios( cCadena )
return strtran( cCadena, Space(1), Space(0) )
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: function to supress intermediate spaces
Also
CharRem( <cDelete>, <cString> ) --> cResult
Examples
CharRem( " ", "One Two Three" ) --> "OneTwoThree"
CharRem( "a", "Banana" ) --> "Bnn"
CharRem( <cDelete>, <cString> ) --> cResult
Examples
CharRem( " ", "One Two Three" ) --> "OneTwoThree"
CharRem( "a", "Banana" ) --> "Bnn"
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- carlos vargas
- Posts: 1421
- Joined: Tue Oct 11, 2005 5:01 pm
- Location: Nicaragua
Re: function to supress intermediate spaces
Esta es una función que cambia espacios de mas de uno a uno.
lo uso mucho con instrucciones sql.
lo uso mucho con instrucciones sql.
Code: Select all
FUNCTION TrimSpace( cString )
DO WHILE AtNum( " ", cString ) > 0
cString := StrTran( cString, " ", " " )
ENDDO
RETURN cString
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
Carlos Vargas
Desde Managua, Nicaragua (CA)
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: function to supress intermediate spaces
I vote for Jack's version:
STRTRAN(var," ","")
The simpler, the better.
STRTRAN(var," ","")
The simpler, the better.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: function to supress intermediate spaces
Carlos Vargas solution is better
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: function to supress intermediate spaces
For this purpose you may consider usingcarlos 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
FUNCTION TrimSpace( cString ) DO WHILE AtNum( " ", cString ) > 0 cString := StrTran( cString, " ", " " ) ENDDO RETURN cString
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.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: function to supress intermediate spaces
Where I can find this function?nageswaragunupudi wrote:For this purpose you may consider usingcarlos 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
FUNCTION TrimSpace( cString ) DO WHILE AtNum( " ", cString ) > 0 cString := StrTran( cString, " ", " " ) ENDDO RETURN cString
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.
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: function to supress intermediate spaces
Elvira said:
Is there a function to remove the intermediate spaces from a string ?
I took Elvira's statement to mean that he want to remove all spaces, but I admit it is not clear. Removing adjacent duplicates is a different task.Nages said:
This is a highly optimized function specially meant for removing adjacent duplicate characters.
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: function to supress intermediate spaces
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
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: function to supress intermediate spaces
You're right! Look at this sample:nageswaragunupudi wrote:But CharRem() function specially made for such purposes and more efficient.
Code: Select all
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
Code: Select all
1.36 0
0.00 0
EMG
Re: function to supress intermediate spaces
Wow! ++++1
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: function to supress intermediate spaces
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?
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?