How to get SubstringValues from Textbox - c#-4.0

len = int.Parse(tE1Clt.Text);
front=int.Prase(tE_Fstng.text);
string result = tE3_Series.Text.Substring(front, len);
tE1_Sub.Text = result.ToString();
I'm getting error
[index and length must refer to a location within the string. Parameter name: `length`]

if (TeInput.Text.Length > 1)
{
string Input = TeInput.Text, Store1 = string.Empty, store2 = string.Empty;
int Start = 0, End = 0;
Start = int.Parse(TeStart.Text);
End = int.Parse(TeEnd.Text);
string Output = TeOutput.Text;
Store1 = Input.Remove(0, Start).Trim();
store2 = Store1.Remove(Store1.Length-End).Trim();
TeOutput.Text = store2;

You can do like this,
var str = "----takemeout----";
var start = str.IndexOf('t'); // start index of first t
var length = 9; // length of takemeout string
var result = str.Substring(start, length);
Value or result will be "takemeout"

Related

Convert 3 output to one input at NODE-RED

Question is about Node-RED for raspberry pi 3. I have 3 input that give acceleration of X,Y,Z axis. I want to make one output from these 3 inputs. For this , I use √X^2+Y^2+Z^2 formula. According to my function my output is still 3 piece and giving NaN output when i debug. What should i do in Acc to Freq function
Here is my collecting X,Y,Z info from my sql.
var str = msg.payload;
str = str[0]['IX']; // Choose last data from IX column
a = str * 10; // Scaling the value
msg.payload = a
return msg;
var str = msg.payload;
str = str[0]['IY']; // Choose last data from IY column
b = str * 10; // Scaling the value
msg.payload = b
return msg;
var str = msg.payload;
str = str[0]['IZ']; // Choose last data from IZ column
c = str * 10; // Scaling the value
msg.payload = c
return msg;
And the function that i m try to calculate one output ( Acc to Freq )
var str = msg.payload;
var a;
var b;
var c;
str = Math.pow(a^2+b^2+c^2);
d = str * 10;
msg.payload = d;
return msg;
The point to remember is that a function node runs every time a message arrives, if you send it 3 separate messages then it will run 3 times. Also each function node is totally independent of all others, you can't declare a variable in one and use it in another (well there is something called the Context, but that's not particularly useful here)
You've not actually shown your flow so we are going to have to guess a little here, but you imply that all the starting values are coming from a single SQL query that returns multiple columns. If this is the case then you have 2 options.
Just do all the calculations in one place e.g. one function node with the following:
var str = msg.payload;
var strA = str[0]['IX']; // Choose last data from IX column
var a = strA * 10; // Scaling the value
var strB = str[0]['IY']; // Choose last data from IY column
var b = strB * 10; // Scaling the value
var strC = str[0]['IZ']; // Choose last data from IZ column
var c = strC * 10; // Scaling the value
var strC = Math.pow(a^2+b^2+c^2);
var d = strC * 10;
msg.payload = d;
return msg;
You can run the output of your current 3 function nodes into a Join node set to collect 3 values. This will generate a new msg object with a payload containing an array of the 3 values. You can then modify your final function node as follows:
var a = msg.payload[0];
var b = msg.payload[1];
var c = msg.payload[2];
var d = Math.pow(a^2+b^2+c^2) * 10 ;
msg.payload = d;
return msg;

Swift, use string name to reference a variable

Plan to use a string value to for referencing which variable I want to update. Combining string from a few different user selected sources. To many possibilities to use if/case statements. Thanks in advance
var d1000: Int = 0
// ...
var d1289: Int = 0
// ...
var d1999: Int = 0
var deviceIDtype: Character = "d" // button press assigns some value, d used for example
var deviceIDsection: String = "12" // button press assigns some value, 12 used for example
var deviceID: String = "89" // button press assigns some value, 89 used for example
var ref:String = ""
func devName(dIDt:Character, dIDs: String, dID: String) -> String {
var combine: String = String(dIDt) + (dIDs) + (dID)
return (combine)
}
ref = devName(deviceIDtype, dIDs: deviceIDsection, dID: deviceID) // ref equals d1289 in this example
// d1289 = 1234 // trying to set this using the ref variable value, failed attempts below
/(ref) = 1234 // set d1289 variable to equal "1234"
"/(ref)" = 1234 // set d1289 variable to equal "1234"
get(ref) = 1234 // set d1289 variable to equal "1234"
get.ref = 1234 // set d1289 variable to equal "1234"
It is possible!!!
let index = 1000
if let d1000 = self.value(forKey: "d\(index)") as? Int {
// enjoy
}
How about using a dictionary, [String : Int]?
This will allow you to achieve what you want - storing values for different keys.
For example, instead of using
var d1000 = 0
var d1289 = 0
var d1999 = 0
You could use
var dictionary: [String : Int] = [
"d1000" : 0,
"d1289" : 0,
"d1999" : 0
]
To store a value in the dictionary, just use
dictionary[key] = value
//for example, setting "d1289" to 1234
dictionary["d1289"] = 1234
and to get the value from the dictionary, use
let value = dictionary[key]
//for example, getting the value of "d1289"
let value = dictionary["d1289"]
So, you could use something like this
//initialize your dictionary
var myDictionary: [String : Int] = [:]
//your key initialization data
var deviceIDtype: Character = "d"
var deviceIDsection: String = "12"
var deviceID: String = "89"
var ref: String = ""
//your code
func devName(/*...*/){/*...*/}
ref = devName(/*...*/)
//set the key ref (fetched from devName) to 1234
myDictionary[ref] = 1234
Just as a side note, you could really clean some of your code
func devName(type: Character, section: String, id: String) -> String{
return String(type) + section + id
}
//...
let key = devName(deviceIDtype, section: deviceIDsection, id: deviceID)
let value = 1234
myDictionary[key] = value

Error parsing string to int in Podio

Anyone knows why the calculation field returns an error when converting a string into an integer?
var $prix = Max of Prix de vente; //Value is 2000.00
var $titre = All of Nom du produit;
var $nbr_heure = $titre[0].substring(0, 3).trim(); //Value is "25"
parseInt($nbr_heure)
parseInt($prix) returns 2000
I have tried parseFloat() and Number(). It seems like as soon as it tried to convert a string, it doesn't process.
My static workaround
var $prix = Max of Prix de vente;
var $titre = All of Nom du produit;
var $nbr_heure = $titre[0].substring(0, 3).trim();
var $taux_horaire = 0;
//Conversion stupide manuelle
if($nbr_heure == "25")
$taux_horaire = $prix / 25;
else if($nbr_heure == "50")
$taux_horaire = $prix / 50;
else if($nbr_heure == "100")
$taux_horaire = $prix / 100;
else
$taux_horaire = 89;
$taux_horaire;
More info, if you do this:
$prix + parseInt($nbr_heure); //Same error
and
$prix + $nbr_heure; //Gives 200025 (String concatenation)
Thank you for any feedback!
You are getting the error because parseInt() is returning NaN instead of an actual number. Or because your substring call is failing.
If your $titre field doesn't contain a value your substring call will fail. So make sure to check in your calculation that it is working with a value and not undefined.
In a similar vein parseInt will return NaN if you call it with an empty string.

Compare to string of names

I am trying to compare the names of two strings, and trying to pick out the name that are not included in the other string.
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result(h) = main_name;
h = h+1;
end
end
but it keeps returning the entire string as result, the main string contain roughly 1000 names, the images name contain about 300 names, so it should return about 700 names in result but it keep returning all 1000 names.
I tried your code with small vectors:
main = ['aaa' 'bbb' 'ccc' 'ddd'];
image = ['bbb' 'ddd'];
name_size_main = size(main,2);
name_size_image = size(image,2);
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result(h) = main_name;
h = h+1;
end
end
I get result = 'aaaccc', is it not what you want to get?
EDIT:
If you are using cell arrays, you should change the line result(h) = main_name; to result{h} = main_name; like that:
main = {'aaa' 'bbb' 'ccc' 'ddd'};
image = {'bbb' 'ddd'};
name_size_main = size(main,2);
name_size_image = size(image,2);
result = cell(0);
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result{h} = main_name;
h = h+1;
end
end
You can use cells of string along with setdiff or setxor.
A = cellstr(('a':'t')') % a cell of string, 'a' to 't'
B = cellstr(('f':'z')') % 'f' to 'z'
C1 = setdiff(A,B,'rows') % gives 'a' to 'e'
C2 = setdiff(B,A,'rows') % gives 'u' to 'z'
C3 = setxor(A,B,'rows') % gives 'a' to 'e' and 'u' to 'z'

number of rows of an ft searched view

I've a view on which I performed a search. I would like to know how many rows this view has after this search. I tried with rows = view1.getEntryCount();
But this gives the number of lines of the "original" view, not the result of my search.
edit
The following works but isn't verry efficient.
Any better idea ?
productTest=sessionScope.get("product");
landTest=sessionScope.get("country");
var length = view1.getEntryCount();
var entries = view1.getAllEntries();
var i = 0;
var rows = 0;
var currentEntry = entries.getFirstEntry();
while(i < length){
land = currentEntry.getColumnValues().elementAt(0);
prod = currentEntry.getColumnValues().elementAt(1);
if (land == landTest & prod == productTest)
{
rows++;
}
currentEntry = entries.getNextEntry();
i++;
}
viewScope.queryString = rows; `
I found this on my blog. Try if if it still works:
var entryCount = viewData.getEntryCount();
var viewControl = getComponent( 'viewControlId' );
var rowCount = viewControl.getRowCount();
// If search is active -> rowcount, else entrycount
var count = ( viewControl.getDataSource().getSearch() ) ? rowCount : entryCount;
please try
rows = view1.getrowlines

Resources