Jump to content
UBot Underground

[library] Strings


Guest Jim

Recommended Posts

uLib Strings

latest version: 2009.12.8

 

Download: ulib_strings.ubot

 

This library includes commonly used string functions.

 

Currently implemented:

- replace - simple string replace

- length - gets the length of a string

- find - finds the position of a string within another string

- find from - same as 'find' but with a parameter for an index to start from

- substring - gets part of a string from a position for a certain length

- substring (alt) - gets part of a string from one position to another position

- trim - removes leading and trailing spaces from a string

 

Let me know any other string functions you guys might find useful that I can implement for this library.

 

If you have any problems or questions, let me know.  Enjoy. ;)

Link to post
Share on other sites

Cheers for this :)

 

Just a quick question if I may.

 

The substring sub, it's return node is

"{1}".substr({2},{3})

#str

#start

#length

 

My question is to do with the 'return' node. I think it is a new feature as it isn't in the 'commando' guide or the wiki (that I can see). Anyway, the 'substr' is Javascript I believe? Am I correct in thinking we can put any valid javascript in a return node?

Link to post
Share on other sites

Answer to my question. Yes the return field can take any Javascript

 

Attached is the test, substring that takes a string and startpos and will return the substring from start position to end. Saves you having to work out the length.

 

Note the #str variable should be passed in as "this is my string", as the " are not added in the sub.

 

Again thanks for adding this library, you have increased the usefulnes of Ubot a million times to me and making it easier and quicker to do things.

 

 

Link to post
Share on other sites

You can use $eval to run javascript - it's useful for a lot of things. My libraries are mostly just wrappers for javascript so far ::)

 

I'm going to add a 'left' and 'right' substring functions to the library to easily substring the left or right side of a string. Trying to think of any other functions I can write.

Link to post
Share on other sites
Guest turbolapp

I have visited this thread a few times now hoping a light would go off as to what the hell you guys are talking about.

 

I'm sad to say I am still in the dark.  Anyone care to enlighten the non programmer here?

Link to post
Share on other sites

^ I felt like that too. Download the encoding library as it includes an example which should help.

 

Basically, if you have ever wanted to do something in Ubot but found there isn't a straight forward way to do things, you can know add the functionality yourself.

 

Just create a library, add the functionality you require using Javascript.

 

Now in any bot you write you can this added functionality just as you would a normal ubot command.

 

 

I will upload an example tonight that uses this string library as it really is a useful library to use (once you have got your head round it).

 

 

Link to post
Share on other sites

Can't add this into new scripts after the most recent ubot update.  The current ones inside a script work and I can still include it, but when I try to click on ulib_strings through run sub I get a huge error every single time.  Doesn't matter if its an older script or a brand new one, same thing.  I've attached an image of the error if you want to take a look.  Let me know if I should post this in the bug report section instead.

Link to post
Share on other sites
  • 4 weeks later...
  • 2 weeks later...
  • 2 weeks later...

Have discovered an issue using javascript in an eval function.

 

I was having an issue passing in a string that contained " and '. Found out I have to escape these manually using the Text Constant > $replace feature (i.e. replace " with \")

 

However, I found out after much swearing and infuration, that if you pass this escaped string into a sub in the string lib that returned a string, then the returned string lost it's encoding. So I had to re-escape it all.

Link to post
Share on other sites

Split would be nice. That is, being able to split a string up into multiple pieces based on a char and then putting it all into a list. Not sure that's technically possible right now tho :)

 

G-Man

Have you tried "add to list >> list from text"?

Link to post
Share on other sites
  • 3 weeks later...

I must be doing something wrong, because I can only get the subs in the strings library to return "undefined" as the return value.

 

I've attached a screenshot of a test script that browses to google, tries to find the position of the letter "e" within the string "abcdefgh" and then enters the return value into the google search field. I must be making some stupid mistake but I can't figure out what it is.

post-466-12667259520705_thumb.png

Link to post
Share on other sites

Don't know why, but the issue is todo with the fact you are passing in straight text and not variables.

 

At a guess I would say it is how uBot stores strings as variables and how it deals with text.

 

Anyway, set 'abcdef' as a variable and set 'e' as a variable and it will work.

 

 

For testing, right clicking a and selecting run node, you can then right click any variable and select insert string, to see what that variable currently has been set to. Make sure you cancel out the window, otherwise you will replace the variable with a string.

Link to post
Share on other sites

No worries, any additional information on what was causing your issue?

 

Not sure yet, but I think it has something to do with how Ubot and javascript interact. The interesting thing is that the Ubot tech support has the exact same problem, so it appears to be a common and reproducible issue. This should hopefully help with debugging.

 

PS - Please check your mail :)

Link to post
Share on other sites

IF based on part of URL

 

For exampel i have a list of urls that i want to do some tasks on.

ANd i want to LOOP it like this:

nav-> next list item

 

IF in url aaa.html then RUN SUB1

IF in url bbb.html then RUN SUB2

etc

 

 

i tried messing with stings library a bit but didnt accomplish it. Anybody could help maybe?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...