[Gambas-user] RC2 split Function (same as in RC1, may be before also)

Mike Keehan mike_keehan at ...679...
Mon Nov 8 23:11:23 CET 2004


Charlie Reinl wrote:
>>Charlie Reinl wrote: 
>>
>>>Salut Benoit, 
>>> 
>>>take that line : 
>>> 
>>>Picture = Picture["gambas.png"] 
>>> 
>>>and split here by "="   
>>> 
>>>from sLine = "Picture = Picture[\"gambas.png\"] 
>>> 
>>>you get  
>>>"Picture " and " Picture[\"gambas.png\"]" 
>>>"Picture" and "Picture[\"gambas.png\"]" 
>>>thats it, you should get . 
>>> 
>>>The blanks left- and right from '=' should not be in the results. 
>>> 
>>>NO? 
>>> 
>>>Amicalment 
>>>Charlie 
>>
>>No, I don't think so. 
>>
>>If the 'split' string is " = " (that is, space - equals - space) then  
>>you would get what you want, but splitting by "=" alone should leave  
>>all the other characters in the split up strings, including leading an  
>>trailing spaces. 
>>
>>If you need to get rid of the spaces, you can use Trim(). 
>>
>>Mike. 
> 
>  
> Sorry, 
>  
> but what is the return if I split with a blank (' ') 
> sLine = "Picture = Picture[\"gambas.png\"]    " 
>  
> Picture 
> = 
> Picture[\"gambas.png\"] 
> ' ' 
> ' ' 
>  
> unquated blanks have no value, so they must be striped. 
>  
> Amicalment 
> Charlie 

I disagree.  Blanks _do_ have a value, they are part of the string.

The only character that should not be in the output is the separator. 
  All other characters should still be in the output strings.

If the space characters are not wanted in your application, then use 
Trim() to remove them.  Other people will want the spaces - I 
certainly do in some places.  And when I don't want leading/trailing 
spaces, I use trim().

Try split() in other languages - awk, VB, or strtok() in C.  They all 
keep the space characters in the output strings when the separator is 
a single character (but not a space char - this tends to be special).

Mike.




More information about the User mailing list