Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 12-25-2008, 05:04 AM   #1 (permalink)
Newbie
 
Join Date: Jan 2004
Posts: 51
Send a message via ICQ to Nemikal
Default Convert/replace characters in a string?

Hi all. I've recently scripted a component to a custom profile system I've been testing on my shard. Everything works quite well, however I have problem when it comes to saving information to a string, and then parsing that string into a URL.

Example is below:

Code:
              this.AddHtml(15,51,270,20,"<A HREF=\"http://www.(edited for advertisement)+ temp + "\">Click for " + temp + "'s Webpage",false,false);
As seen here, this bit of HTML is empoyed in a gump, which references an account tag, as follows:

Code:
string temp=((Account)((Mobile)who).Account).GetTag("PROFILELINK" + who.Name);
Basically, a player has the option of saving a "profile", a string that contains, at the moment, any collection of characters, which is then parsed directly into the above line of code in a gump, which ultimately creates a clickable URL.

As I said, this works wonderfully as is. For example, this code would automatically check the string stored as the PROFILELINK account tag, parse that string into the URL, and then open. However, with browsers other than Internet Explorer, when a space is used to seperate two words, the gump simply fails to open the browser (obviously due to the browser recognizing bad syntax in the URL created by above code. Mozilla/FireFox does not like white spaces!).

I've tested using an underscore ( _ ) between two words as opposed to a simple space, and voila, it works fine for just about every browser (save for Chrome). Thus, my issue inherent is as follows:

How can I have the line of code in the gump recognize white space as an underscore? I think this approach would be more practical than saving the string's white space as underscores, or even my last resort, posting a disclaimer that instructs players to use an underscore instead of a space.

And for the inquiring minds wondering why on earth I'd want a space between two words that are used to create a viable web-link, the website I created to use this system recognizes spaces between words automatically as underscores. If it wasn't for the FireFox issue, the script would be fine as is.

Any help would be duly appreciated. Again, I'm essenitally just looking for a way to either replace spaces in a string with underscores automatically, or have an AddHtml gump line of code that automatically recognizes and replaces spaces with underscores.

Oh, and Merry Christmas to those Christian folk out there!
Nemikal is offline   Reply With Quote
Old 12-25-2008, 05:56 AM   #2 (permalink)
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 12,209
Send a message via Yahoo to Lord_Greywolf
Default

you can do a check on the string entered, checking for bad characters and speaces, etc
and if in there tell them they have to remake it

looke at NameVerification.cs in the misc directory and how they do it
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Old 12-26-2008, 11:04 AM   #3 (permalink)
Forum Novice
 
Mideon's Avatar
 
Join Date: May 2005
Location: Canada
Age: 26
Posts: 684
Send a message via MSN to Mideon
Default

Strings are also like "arrays" of "char" type data.

So consider string temp = "blah";

temp[0] (this value is b)
temp[1] (this value is l)
etc.

So what you could do is...

Code:
foreach(char c in temp)
{
    if(c == ' ') //if char is whitespace
        c = '_'; //replace with underscore;
}
Something to this effect should work.

But there also should be many Methods in the String class that could help with this as well. Google C# string manipulation tutorial and you should find dozens of links....I wish I knew the methods, but I've not done much string manipulation in a long time.

Hope that helps and merry xmas if you celebrate.
__________________
tleauo.com -- An Ultima Online Roleplaying Environment
Mideon is offline   Reply With Quote
Old 12-27-2008, 01:13 PM   #4 (permalink)
ConnectUO Creator
 
Join Date: Jan 2004
Age: 29
Posts: 6,076
Default

Quote:
Originally Posted by Mideon View Post
Strings are also like "arrays" of "char" type data.

So consider string temp = "blah";

temp[0] (this value is b)
temp[1] (this value is l)
etc.

So what you could do is...

Code:
foreach(char c in temp)
{
    if(c == ' ') //if char is whitespace
        c = '_'; //replace with underscore;
}
Something to this effect should work.

But there also should be many Methods in the String class that could help with this as well. Google C# string manipulation tutorial and you should find dozens of links....I wish I knew the methods, but I've not done much string manipulation in a long time.

Hope that helps and merry xmas if you celebrate.
wow....



you should just use string.Replace
Code:
temp = temp.Replace(' ', '_');
__________________
Jeff Boulanger
ConnectUO - Creator/Core Developer
ConnectUO Swag/Merchandise

Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 12-29-2008, 06:52 AM   #5 (permalink)
Newbie
 
Join Date: Jan 2004
Posts: 51
Send a message via ICQ to Nemikal
Default

Haven't been able to take a look at this since my video card died.

Thanks Mideon, Grey!

I didn't know it was so easy Jeff. Thanks a ton
Nemikal is offline   Reply With Quote
Old 12-30-2008, 03:10 PM   #6 (permalink)
Forum Novice
 
Mideon's Avatar
 
Join Date: May 2005
Location: Canada
Age: 26
Posts: 684
Send a message via MSN to Mideon
Default

Quote:
Originally Posted by Jeff View Post
wow....



you should just use string.Replace
Code:
temp = temp.Replace(' ', '_');
LOL, I was just explaining how it works on a core level. But I'm glad you mentioned the method name, I couldn't for the life of me remember.
__________________
tleauo.com -- An Ultima Online Roleplaying Environment
Mideon is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5