[Gambas-user] string conversion
Dimitris Anogiatis
dosida at ...626...
Thu Nov 12 21:35:27 CET 2009
Hey Matti,
you might want to roll a string conversion function of your own.
The Replace function might be of particular use to you.
You can read about it over here
http://www.gambasdoc.org/help/lang/replace
and you can also find all the other string related functions over here
http://www.gambasdoc.org/help/cat/string
if for example you want to replace all the spaces in your string with %20
you would call
'String array that will hold the characters you want to replace
Dim tmpChar as NEW String[]
Dim iterator as Integer
Dim sFilename as String
'the value of your sFilename
sFilename = "/home/username/Meine Bilder/öffentliche Fotos übertragen/015
das Schönste.jpg"
'Add the characters you want to replace
tmpChar.Add("ö")
tmpChar.Add("ü")
'Loop through the array and replace the string characters that correspond to
the array characters
'with their hexadecimal values precedded by a % sign
FOR iterator = 0 to tmpChar.Count -1
'set the string equal to the resulting string from the Replace$ Function
sFilename = Replace$( sFilename,tmpChar[iterator],"%" &
Hex$(Asc(tmpChar[iterator])))
NEXT
'to show you the finished string
PRINT sFilename
so you could also just make a small array with all the characters you want
to
change and then do a sequence of Replace$ calls replacing them with
I hope these guidelines help you more (and confuse you less)
Regards
Dimitris
On Thu, Nov 12, 2009 at 1:14 PM, Matti <math.eber at ...221...> wrote:
> Well, after some thoughts, I can answer myself.
>
> I tried this example:
>
> sFilename = "/home/username/Meine Bilder/öffentliche Fotos übertragen/015
> das Schönste.jpg"
> i = 1
> WHILE i < Len(sFilename)
> sChar = Mid$(sFilename, i, 1)
> IF Asc(sChar) > 122 THEN
> sFilename = Left$(sFilename, i - 1) & "%" & Hex$(Asc(sChar)) &
> Right$(sFilename, Len(sFilename) - i)
> ELSE IF sChar = " " THEN
> sFilename = Replace$(sFilename, " ", "%20")
> ENDIF
> i = i + 1
> WEND
> sOut = "file://" & sFilename
> PRINT sOut
>
> and it seems to work ok and reasonably fast.
> But if you have better ideas, you're welcome!
>
>
>
> Matti schrieb:
> > Hi,
> >
> > I'm looking for a string conversion function for URIs.
> > It should work like CGI.Encode, but
> > - don't transform slashes "/"
> > - transform spaces " " not to "+" but to "%20".
> >
> > Couldn't find anything in Gambas. Maybe a shell command?
> >
> > Thanks
> > Matti
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list