Converting strings

DarkSir

New member
Well, I've been lurking here for a couple of weeks now. Guess it's finally time to post. :)

I was looking through the ASH reference, and I didn't see this feature, but I'm not sure how up-to-date the reference is.

What I'd like to be able to do is convert a string to a + delimited list. Basically, Convert:

Code:
The quick brown fox jumped

to

Code:
The+quick+brown+fox+jumped

This may already be built in, but I doubt it. Figured I'd ask before I started writing the function.
 

Tirian

Member
It doesn't exist. I had occasion to check the reference a few days ago and thought that it was quite up-to-date, although four or five new functions have been added in the past couple days and the reference probably won't get updated until the next public release at the earliest.

Out of curiosity, what are you planning on using this functionality for? I hope we can come up with a workaround for it, because I think you'll find that writing your own function to do this will be extraordinarily cumbersome.
 

DarkSir

New member
Well, the idea is to convert text to something that can be used in a URL. My personal plan is to write a function that lets me send a gift package. I had an occasion recently, where I needed to send a gift package to 50 clan members. But I wanted a specific Inside message for the packages, so the "send" command was insufficient. If one could convert a string to a plus delimited list, it could be inserted into the URL as part of a function...

I hope I'm making sense.
 

Veracity

Developer
Staff member
so, basically, what you want is a function:

string url_encode( string input );

...which will do standard encoding for you.

Considering that we now allow people to invoke arbitrary URLs, I guess this is reasonable. OK, I have checked in some new ASH functions. Once you get a version of KoLmafia that included them, this script:

Code:
String input = "This is a string with spaces in it.";
String output1 = url_encode( input );
String output2 = url_decode( output1 );

print( "input = " + input );
print( "url_encoded = " + output1 );
print( "url_decoded = " + output2 );
print( input == output2 );
generates the following output:

>url.ash
input = This is a string with spaces in it.
url_encoded = This+is+a+string+with+spaces+in+it.
url_decoded = This is a string with spaces in it.
true
Script succeeded!
 

macman104

Member
[quote author=DarkSir link=topic=178.msg883#msg883 date=1148520365]
You are my hero, Veracity :)

I eagerly await 7.7 :)
[/quote]When it comes to ASH scripting, she is the leader, dictator, ruler, and anything else that affects ASH.
 
Top