Jump to content
UBot Underground

Sanitizer function not properly responding as I planned


Recommended Posts

Hello guys..

Im doing functions to refactor my code and make it more clean. But I am struggling on how to do it with UBot.

I am doing this:

define $Sanitize companies variables(#sanitize_companies) {
    set(#sanitize_companies, $trim(#sanitize_companies), "Global")
    set(#sanitize_companies, $replace(#sanitize_companies, ",", ". "), "Global")
    set(#sanitize_companies, $replace(#sanitize_companies, "\"", $nothing), "Global")
    return(#sanitize_companies)
}

And testing it with this:

set(#company_name, "\"something with\" and some, commas that define, more content and finally another \"", "Global")
set(#company_name, $Sanitize companies variables(#company_name), "Global")

Its not working for me,

I know I am doing something wrong but I cannot detect it.

Link to post
Share on other sites

When adding a parameter to a function, you don't need to pass it to a variable from inside the function, you can just use it as is (it's a common misconception, most tutorials are quite misleading about this).

 

Here you go, try this:

 

set(#company_name"\"something with\" and some, commas that define, more content and finally another \"""Global")
set(#company_name$Sanitize companies variables(#company_name), "Global")
define $Sanitize companies variables(#sanitize_companies) {
    return($replace($replace($trim(#sanitize_companies), ",""."), "\""$nothing))
}

 

Let me know if you have any questions.

 

Marton

 

p.s.: if any mod reads this, I think this topic should be moved to Scripting main forums

Link to post
Share on other sites

Wow, thanks a lot.

So my mistake was setting(using set) inside the function instead of clearly just returning concatenated functions.

Right?

Link to post
Share on other sites

Wow, thanks a lot.

So my mistake was setting(using set) inside the function instead of clearly just returning concatenated functions.

Right?

 

No problem.

 

Well, I wouldn't call it a mistake, but it's not needed. You can fix your original code by changing all three set commands in your function to "Local". Try it, it will work.

 

Mine is just a bit more optimized, that's all.

 

Marton

Link to post
Share on other sites

Your method is what I want to learn eventually.

Those smart decisions for refactoring.

Where can I learn more about it?

How can I google that for javascript or PHP?

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...