How do I change these "if"s into a selector string - coffeescript

I have these if statements, and I am sure it can be shortened. I am very new to coffeescript (and to javascript as well).
$ ->
url = window.location.href.toString()
urlpart = url.split("//")
urlpart = urlpart[1].split("#")
$("#mainTabs a[href=\"#payments\"]").tab "show" if urlpart[1] is "payments"
$("#mainTabs a[href=\"#invitations\"]").tab "show" if urlpart[1] is "invitations"
$("#mainTabs a[href=\"#orders\"]").tab "show" if urlpart[1] is "orders"
$("#mainTabs a[href=\"#campaigns\"]").tab "show" if urlpart[1] is "campaigns"

You could use string interpolation to build the jQuery selector, something like:
url = window.location.href.toString()
urlpart = url.split("//")
urlpart = urlpart[1].split("#")
$("#mainTabs a[href='##{urlpart[1]}']").tab "show"
The #{...} bit inside a double quoted string is interpolation. I also switched to single quotes inside the selector to cut down on the backslash noise.

Related

Using 'N in ADO.recordset.filter string

I have a VB6 ADO recordest that contains unicode text and need to filter it using .filter method with unicode text. I tried to use N' function but it does not work when I use it in .Filter text
Rs.filter = "Name = 'Apple'" 'OK
Rs.Filter = "Name = N'英語'" 'Not working for filter text
How I should wrap the text or I need to use another function?

How to cut a string from the end in UIPATH

I have this string: "C:\Procesos\rrhh\CorteDocumentos\Cortados\10001662-1_20060301_29_1_20190301.pdf" and im trying to get this part : "20190301". The problem is the lenght is not always the same. It would be:
"9001662-1_20060301_4_1_20190301".
I've tried this: item.ToString.Substring(66,8), but it doesn't work sometimes.
What can I do?.
This is a code example of what I said in my comment.
Sub Main()
Dim strFileName As String = ""
Dim di As New DirectoryInfo("C:\Users\Maniac\Desktop\test")
Dim aryFi As FileInfo() = di.GetFiles("*.pdf")
Dim fi As FileInfo
For Each fi In aryFi
Dim arrname() As String
arrname = Split(Path.GetFileNameWithoutExtension(fi.Name), "_")
strFileName = arrname(arrname.Count - 1)
Console.WriteLine(strFileName)
Next
End Sub
You could achieve this using a simple regular expressions, which has the added benefit of including pattern validation.
If you need to get exactly eight numbers from the end of file name (and after an underscore), you can use this pattern:
_(\d{8})\.pdf
And then this VB.NET line:
Regex.Match(fileName, "_(\d{8})\.pdf").Groups(1).Value
It's important to mention that Regex is by default case sensitive, so to prevent from being in a situations where "pdf" is matched and "PDF" is not, the patter can be adjusted like this:
(?i)_(\d{8})\.pdf
You can than use it directly in any expression window:
PS: You should also ensure that System.Text.RegularExpressions reference is in the Imports:
You can achieve it by this way as well :)
Path.GetFileNameWithoutExtension(Str1).Split("_"c).Last
Path.GetFileNameWithoutExtension
Returns the file name of the specified path string without the extension.
so with your String it will return to you - 10001662-1_20060301_29_1_20190301
then Split above String i.e. 10001662-1_20060301_29_1_20190301 based on _ and will return an array of string.
Last
It will return you the last element of an array returned by Split..
Regards..!!
AKsh

JAVASCRIPT: Replace a single character into a <p>

I've got a word in an HTML paragraph. For example 'string':
<p id="myWord">string</p>
I want to change only a character of that word. For example 'strong':
So I add an html button that calls a function:
<button onclick="myFunction">replace 'i'</button>
the function in JS is this but it can't access to the fourth character of myWord:
function myFunction{
document.getElementById("myWord[3]").innerHTML = 'o';
}
Here is the unWorking fiddle: https://jsfiddle.net/su3Lrezr/4/
How can I access to a index of a word in a html paragraph? I already tried to convert myWord into an array with split() method but it doesn't work.
Thanks everybody
Array method:
You'll want to split the string at value 'i' Then rejoin them together with an 'o' in the middle. Then update your innerHTML. You will need the split() function. This will work:
function myFunction(){
var word = document.getElementById('myWord').innerHTML;
var result = word.split('i');
var newword = result[0] + "o" + result[1];
document.getElementById('myWord').innerHTML = newword;
}
Also, as a commenter has mentioned your syntax for calling functions is wrong. You must call functions like this: myFunction() and declare them like this: function myFunction(){ }

Show nothing if the item doesn't have a date

I want my code to display nothing if it doesn't have a date.
Here is my code:
=format(IIF(Fields!Phase.Value = "Pre-Feasibility" OR Fields!Phase.Value = "Selection", Fields!PreFeasibilityCurrentTargetDate.Value, IIF(Fields!Phase.Value = "Feasibility" OR Fields!Phase.Value = "Definition", Fields!FeasibilityCurrentTargetDate.Value, IIF(Fields!Phase.Value = "Implementation", Fields!ImplementationCurrentTargetDate.Value, ""))), "dd-MMM-yy")
Because I am formatting it to dd-MMM-yy, it displays that when the item doesn't have a date. How can i have this changed to display nothing if it doesn't have a date.
Change the blank values of your expression to nothing
=Iif(Fields!Phase.Value="Operation","-", format(
IIF(Fields!Phase.Value = "Pre-Feasibility" OR Fields!Phase.Value = "Selection",
Fields!PreFeasibilityCurrentTargetDate.Value,
IIF(Fields!Phase.Value = "Feasibility" OR Fields!Phase.Value = "Definition",
Fields!FeasibilityCurrentTargetDate.Value,
IIF(Fields!Phase.Value = "Implementation",
Fields!ImplementationCurrentTargetDate.Value, Nothing)))
, "dd-MMM-yy") )
I would also advice you to use the field format property instead of the format function inside the value expression. In this case it works even if the field value is blank
check the MSDN form here,
https://msdn.microsoft.com/en-us/library/ms157406.aspx
it clearly mention that "If you specify an invalid format string, the formatted text is interpreted as a literal string which overrides the formatting."
So. you need to check the string after formatting,
IIF(output="dd-MMM-yy","",output)

Regular expression in Smartface

how can I use regex in Smartface for editboxes' text area?
Can someone give an example?
Should I write the expression to the text area directly or it must be done another way?
I don't know what kind of regular expression you need.
A simple usage will be as below :
var price = '$55.99';
var priceRegex = /[(0-9)+.?(0-9)*]+/igm;
var price2 = parseFloat(priceRegex.exec(price));
var myEditbox1 = new SMF.UI.EditBox({
text : price,
top : "20%"
});
var myEditbox2 = new SMF.UI.EditBox({
text : price2,
top : "50%"
});
I used a priceRegex as a regular expression in script file.
You can add these two editbox objects to your page in order to see the result.