error with string variable - string

I'm trying to use a string variable as input to an xml function. When I use this command:
name2_node(i).setTextContent('truck');
there is no error. But when I replace it with:
name2_node(i).setTextContent(type(i,1));
an error occurs like this:
No method 'setTextContent' with matching signature found for class
'org.apache.xerces.dom.ElementImpl'.
The variable type is a string array. In fact when I type type(i,1) in command window the result is:
ans =
string
"truck"
What part am I doing wrong?

Two things:
use a different variable name, type is a built in function which tells you the variable type, hence why it shows "string" in the output.
Then access the cell array of strings with curly braces
vehicletypes = {'car'; 'truck'; 'van'};
name2_node(i).setTextContent(vehicletypes{i,1}); % For i=2, this passes 'truck'

Related

How to replace a single quote with double quotes in ADF dynamic expressions

I am trying to replace single quote in a string with double quote using replace function with data factory expressions.
For example, replace single quote in the following string
hello'world ---> hello''world
#replace(pipeline().parameters.tst,''','''')
The above code is not working. Need help in fixing the code
You can declare a new parameter with the value ' (single quote). You can look at the following demonstration for reference.
I have taken 2 parameters, text with the value hello'world and replace_char with the value '.
I used a set variable activity to store the output of the replace() function (for demonstration) into variable named output (String). Now, I modified the value as:
#replace(pipeline().parameters.text,pipeline().parameters.replace_char,'"')
This successfully helps in replacing a single quote with double quote character.
NOTE: The \ in the output variable value indicates that the " is to be considered as a character inside the string value.
Use two single quotes to escape a ' character in string functions.
For example, expression #concat('Baba', '''s ', 'book store') will return below result.
Baba's book store
https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#escaping-single-quote-character

If i store index number fetched from db in variable & using in select from list by index, m getting err as expected string, int found-Robot Framework

enter image description here
select from list by index ${locator_var} ${inp_msge_type}
--getting error as expected string, int found
select from list by index ${locator_var} 7
-----not getting any error
${inp_msge_type}----contains 7 from DB query the result is stored in this variable, to avoid hard coding we need to do this
Is there any way to write
Do not add links to screenshots of code, or error messages, and format the code pieces accordingly - use the ` (tick) symbol to surround them.
The rant now behind us, your issue is that the keyword Select From List By Index expects the type of the index argument to be a string.
When you called it
Select From List By Index ${locator_var} 7
, that "7" is actually a string (though it looks like a number), because this is what the framework defaults to on any typed text. And so it works.
When you get the value from the DB, it is of the type that the DB stores it with; and probably the table schema says it is int. So now you pass an int to the keyword - and it fails.
The fix is simple - just cast (convert) the variable to a string type:
${inp_msge_type}= Convert To String ${inp_msge_type}
, and now you can call the keyword as you did before.

Matlab - Define variable from strings [duplicate]

If for instance I have a variable xa=2, and then I construct a string by joining 'x' and 'a', how can I make this new string have the value 2?
xa=2;
var=strcat('x','a');
The result of this is var=xa, but what I want is var=2.
Thank you
Use eval():
var = eval(strcat('x','a'));
It will "evaluate" the string 'xa' and translate it to the value of the variable xa.
Source : MATLAB documentation

Convert String type value to a object type VBS

I need to pass an object type value to a procedures, which read from a text file (String fromat).
'param node- Object type
'param txtvalue - String
Function setTexttoElement(nodename, txtvalue)
nodename.Text = txtvalue
End Function
Method is finely works when passing following values
setTexttoElement myElement, abc
But when reading a file it's take String format. So I need to convert first value as Object
"myElement", "abc"
How to solve this?
You will need to create a reference dictionary to convert the text string to an object effectively, as there is no way for vbscript to know what type of object you are passing to the function. For more information: click here.

as3, string to variable

I have array with variable names:
var subjectArray:Array=["subject0","subject1","subject2"];
I need to convert string to var, but following does not work: this[subjectArray[0]] throws an error.
Any thoughts?
That syntax should work. You can check if an object contains a property with a given name with the in keyword. The property does probably not exist.
if (subjectArray[0] in this) {
// do something with this[subjectArray[0]];
}

Resources