I have a string and say I want to check the last 3 digits of the string for some range.
if the string is like sasdaX01, I need to check the last three digits of the string are between X01-X50.
ANy help would be highly appreciated.
The use spl.string::*; line is mandatory and then you extract your last digits with substring(info, length(info) - 3, 3).
An example:
use spl.string::*;
composite TestComposite {
graph
// ... code generating (stream<rstring info> testStream)
() as PrintTestInfo = Custom(testStream as infoEvents) {
logic
onTuple infoEvents : {
rstring lastDigits = substring(info, length(info) - 3, 3);
boolean matched = (lastDigits >= "X01" && lastDigits <= "X50");
println(info + " matched > " + (rstring)matched) ;
} // onTuple infoEvents
} // PrintTestInfo
} // TestComposite
Related
I am opening whatsapp url with text and number.
Issue is i have 2 types of number
+923323789222 & 03323789222
Whatsapp is not opening number starting from 0 so what i need to do is if number have 0 replace it with +92
var url ='whatsapp://send?phone=+923323789222&text=Apna ${widget.data['selererName']} ko ${Ggive.toString()} Rupees dene hein';
in phone when i am passing with +92 its working fine so my question is how can i replace if my number start with 0 and replace with +92
You can just check if your number have 0 in start just replace with +92 and if its not start with 0 then remain it same.
String num = yournumber.toString();
if(num[0] == "0"){
print('have zero');
String numb2 = num.substring(0, 0) + "+92" + num.substring(1);
print(numb2);
num = numb2;
}
var url ='whatsapp://send?phone=${num}&text=Apna ${widget.data['selererName']} ko ${Ggive.toString()} Rupees dene hein';
print(url);
Just use the below code to replace a particular string.
var url ='whatsapp://send?phone=+923323789222&text=Apna ${widget.data['selererName']} ko ${Ggive.toString()} Rupees dene hein';
url.replaceAll('phone=0', 'phone=+92');
You can also use regex for string replacement.
Try this:
String formatPhoneNumber(String phoneNumber) {
if (phoneNumber.length < 1) return '';
// if the phone number doesn't start with 0,
// it is already formatted and we return in the
// way it is.
if (phoneNumber[0] != '0') return phoneNumber;
// if it starts with 0 then we replace the 0 with +92
// and return the new value.
return phoneNumber.replaceFirst(RegExp('0'), '+92');
}
Usage:
print(formatPhoneNumber('+923323789222'));
// OUTPUT: +923323789222
print(formatPhoneNumber('03323789222'));
// OUTPUT: +923323789222
I'm trying to convert list result from tJava Component to json object.
Result from tjava component is below.
[{run_id=5d0753d58d93b71a1d12cc22_, parent_run_id=null, pipe_invoker=scheduled, path_id=shared, count=33, plex_path=null, invoker=abc.com, nested_pipeline=true, duration=355, start_time=2020-11-20T11:17:32.298000+00:00, lable=MP_SQS, state=Completed, key=57694b41ee, root_ruuid=2_ba32ea346}, {run_id=5bd4c6ea346, parent_run_id=null, pipe_invoker=scheduled, path_id=shared, count=33, plex_path=null, invoker=wwr.com, nested_pipeline=true, duration=355, start_time=2020-11-20T11:17:32.298000+00:00, lable=Summary_MP_SQS, state=Completed, key=55dfff4f, root_ruuid=1246d2-8bdc-1846}]
i tried using tConvertType, or in tMapper converting into String then replace all function multiple time and then storing result into json file but noting is working as expected.
End Expected result is json file from above result.
I don't think there is an easy way with a Talend component to do that (but I may be wrong :-) ) :
Put quotes on the keys/value
Replace "=" by ":"
But it can be done with regular Java code, here an example :
String input =
"[{run_id=1111, parent_run_id=null1, pipe_invoker=scheduled1, path_id=shared, count=33, plex_path=null}," +
" {run_id=2222, parent_run_id=null2, pipe_invoker=scheduled2, path_id=shared, count=33, plex_path=null}]";
StringBuilder output = new StringBuilder();
input = input.substring(2,input.length() - 2); // remove "[{" .... "}]"
output.append("[{");
String step1 [] = input.split("\\}, \\{"); // each record, split on "}, {"
int j = 1;
for (String record : step1) {
String step2 [] = record.split(","); // each key/value, split on ","
int i = 1;
for (String keyValue : step2) {
// key=value --> "key":"value"
output.append("\"" + keyValue.split("=")[0].trim() + "\":\"" + keyValue.split("=")[1].trim() + "\"");
if (i++ < step2.length ) {
output.append(",");
}
}
if (j++ < step1.length ) {
output.append("} , {");
}
}
output.append("}]");
/*
output :
[{"run_id":"1111","parent_run_id":"null1","pipe_invoker":"scheduled1","path_id":"shared","count":"33","plex_path":"null"} , {"run_id":"2222","parent_run_id":"null2","pipe_invoker":"scheduled2","path_id":"shared","count":"33","plex_path":"null"}]
*/
Lets say that I have a string:
a="23questions";
b="2questions3";
Now I need to parse 23 from both string. How do I extract that number or any number from a string value?
The following code can extract the number:
aStr = a.replaceAll(new RegExp(r'[^0-9]'),''); // '23'
You can parse it into integer using:
aInt = int.parse(aStr);
const text = "23questions";
Step 1: Find matches using regex:
final intInStr = RegExp(r'\d+');
Step 2: Do whatever you want with the result:
void main() {
print(intInStr.allMatches(text).map((m) => m.group(0)));
}
I have a table column which displays customers full names (first name + last name). However, I want to sort this column first by first name and then by last name. Therefore I added some comparator function in my controller:
_customNameComparator: function(value1, value2) {
// Separate all words of the full name
var aWordsName1 = value1.split(" ");
var aWordsName2 = value2.split(" ");
// Get the last and first names of the two names
var sFirstName1 = value1.substring(0, value1.lastIndexOf(" "));
var sLastName1 = aWordsName1[aWordsName1.length - 1];
var sFirstName2 = value2.substring(0, value1.lastIndexOf(" "));
var sLastName2 = aWordsName2[aWordsName2.length - 1];
// 0 values are equal
// -1 value1 smaller than value2
// 1 value1 larger than value2
if (sLastName1 === sLastName2) {
if (sFirstName1 === sFirstName2) {
return 0;
} else if (sFirstName1 > sFirstName2) {
return 1;
} else {
return -1;
}
} else if (sLastName1 > sLastName2) {
return 1;
} else {
return -1;
}
}
When the column Header is clicked, I try to call
var aSorter = [];
aSorter.push(new sap.ui.model.Sorter("FullName", bDescending, false, this._customNameComparator));
var oBinding = this.byId("tableTargetGroupDetails").getBinding("items");
oBinding.sort(aSorter);
The comparator does not work like this. The sorting is just as usual (by the full name). What do I do wrong?
And btw: I know that this can lead to some wrong sorting (e.g. for last names containing out of two or more words), but since it's "only" the sorting this is fine for me at the moment.
Unless your binding's operationMode is Client, your comparator will probably not work. You can set the mode where you do your binding using { parameters: { operationMode: 'Client' } }.
Hi is it possible to set the time range of a Dojo textTimeBox to 09:00 - 18:30.
I can't find anything in either the Zend or Dojo documentation that show how this can be done or if it can be done.
Many thanks in advance.
You can set max and min constraints for widget:
new dijit.form.TimeTextBox({
name: "prog_val",
value: new Date(),
constraints: {
timePattern: 'HH:mm:ss',
clickableIncrement: 'T00:15:00',
visibleIncrement: 'T00:15:00',
visibleRange: 'T01:00:00',
min:'T09:00:00',
max:'T18:30:00'
}
},
"prog_val");
It does not allow the user to enter data beyond the allowed values.
However this still allows user to scroll to the disabled times, user just cannot select them.
For hiding disabled times you should do some hack :)
You should override _getFilteredNodes method of dijit._TimePicker. For example :
dojo.declare("my._TimePicker", dijit._TimePicker, {
// extend the default show() method
_getFilteredNodes: function (/*number*/start, /*number*/maxNum, /*Boolean*/before) {
// summary:
// Returns an array of nodes with the filter applied. At most maxNum nodes
// will be returned - but fewer may be returned as well. If the
// before parameter is set to true, then it will return the elements
// before the given index
// tags:
// private
var nodes = [], n, i = start, max = this._maxIncrement + Math.abs(i),
chk = before ? -1 : 1, dec = before ? 1 : 0, inc = before ? 0 : 1;
do {
i = i - dec;
var date = new Date(this._refDate);
var incrementDate = this._clickableIncrementDate;
date.setHours(date.getHours() + incrementDate.getHours() * i,
date.getMinutes() + incrementDate.getMinutes() * i,
date.getSeconds() + incrementDate.getSeconds() * i);
if (!this.isDisabledDate(date)) {
n = this._createOption(i);
if (n) { nodes.push(n); }
}
i = i + inc;
} while (nodes.length < maxNum && (i * chk) < max);
if (before) { nodes.reverse(); }
return nodes;
}
});
And you need to set this new class ('my._TimePicker') as a popupClass property of your text time box:
dojo.addOnLoad(function () {
dijit.byId("prog_val").popupClass = "my._TimePicker";
});
And you can see : it works!