what's the easiest way to cut string in Flex ?
I mean, I have a sequence of urls, I want them at most 60 characters length. If they are longer they should be cut and "..." should be added at the end.
<mx:LinkButton label="{bookmarksRepeater.currentItem.name}" click="navigateToURL(new URLRequest(event.currentTarget.label.toString()))" />
thanks
if you can run full flex code in the label="" section, perhaps set the label to this:
it's a conditional statement: if the name length is less than or equal to 60, just use the name, otherwise use the first 57 characters of the name and '...'
bookmarksRepeater.currentItem.name.length <= 60 ? bookmarksRepeater.currentItem.name : bookmarksRepeater.currentItem.name.substr(0, 57) + '...'
substr(startIndex:Number = 0, len:Number = 0x7fffffff):String
Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.
from HERE
Related
While writing tests on an application I have came across a problem.
I need to fetch a number inside a span from the DOM and then assert if the number is between a specific range.
I can do it by using
cy.get('#my_selector').invoke('text').should('be.gt',lower_bound).and('be.lt',upper_bound)
But the issue is the number is comma separated like 5,000. and I'm getting an error as "expected '5,000' to be a number or a date"
Is there any simple short way to convert it into pure numeric
You can use the javascript replace method to remove the comma and then add a + to convert it into a number, like:
cy.get('#my_selector')
.invoke('text')
.then((num) => {
cy.wrap(+num.replace(/,/g, ''))
.should('be.gt', lower_bound)
.and('be.lt', upper_bound)
})
You can use string.replaceAll() to remove the "," then parseInt()
cy.get('#my_selector')
.invoke('text')
.then(str => parseInt(str.replaceAll(',', '')))
.should('be.within', lower_bound, upper_bound)
I am writing a varnish module (VCL) for my backend server. It requires a logic of extracting n characters from a string of undefined length.
I tried regsub() function of vcl with a regex to replace part of the string with empty space.
I need to extract first 20 characters of string. When the string length is 36, i used regex to replace last 16 characters to empty space.
But when length of the string is undefined say 40. i get 24 characters instead of 20. How do i achieve this?
set req.http.mysubstr = regsub(req.http.mystring, ".{16}$", "");
set req.http.mysubstr = regsub(req.http.mystring, ".{($variable)}$", ""); # $variable should be the length of the string - first 20 characters
Use capturing groups:
regsub(req.http.mystring, "^(.{20}).*", "\1")
test it on regex101.com
I am tring to use lpad in progress Db but its not working..
Code:
lpad(act_num, 7, '#')
This code not working , Do we have any alternative way to achieve o/p.
If act_num is 101 then o/P shoud br 7777101.
There is no lpad() function in OpenEdge, but you may be able to use the FILL() function. It takes two inputs: a character string to use as the fill value, and the number of times to repeat the string.
This will add four "7"s to the beginning of act_num, as you described in your question:
DEFINE VARIABLE act_num AS CHARACTER NO-UNDO INITIAL "101".
act_num = FILL("7", 4) + act_num.
MESSAGE act_num VIEW-AS ALERT-BOX.
The fill value can be any string, and not just a single character.
I have a NumericStepper in flex that must accept values between 0 and 999.99.
I tried setting the numericStepper as follows:
<s:NumericStepper id="numStepper" value="#{myValue}" maximum="999.99" snapInterval="0.01" stepSize="0.01" minimum="0"/>
and setting also a NumberValidator attached to it:
var nValidator:NumberValidator = new NumberValidator();
nValidator.source = numStepper;
nValidator.precision = 2;
numericStepper.maxChars=6;
nValidator.decimalSeparator=".";
The thing works but I would like also to directly limit the user input via keyboard in the numeric stepper, so that the user can't type things like "1.4567" but only 1.45.
So I want something to limit the integer and decimal part of the number according to my specifications:
max 3 chars integer part
"." decimal separator
max 2 chars precision
Maybe some regular expression can help?
Thanks
Have you tried...
nValidator.fractionalDigits = 2;
I have a dropdownlist that has the value of two columns in it... One column is a number ranging from 5 characters long to 8 characters long then a space then the '|' character and another space, followed by a Description for the set of numbers.
An example:
12345678 | Description of Product
In order to pull the items for the dropdownlist into my database I need a to utilize a substring to pull the sequence of numbers out only.
Is it possible to write a substring to pull multiple character lengths? (Sometimes it may be 6 numbers, sometimes 5 numbers, sometimes 8, it would depend on what the user selected from the dropdownlist.)
Use a regular expression for this.
Assuming the number is at the start of the string, you can use the following:
^[0-9]+
Usage:
var theNumbers = RegEx.Match(myDropdownValue, "^[0-9]+").Value;
You could also use string.Split to get the parts separated by | if you know the first part is what you need and will always be numeric:
var theNumbers = myDropdownValue.Split("| ".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries)[0];
Either of these approaches will result in a string. You can use int.Parse on the result in order to get an integer from it.
This is how I would do it
string str = "12345678 | Description of Product";
int delimiter;
delimiter = str.IndexOf("|") - 1;
string ID =str.substring(0, delimiter);
string desc = str.substring(delimiter + 1, str.length - 1);
Try using a regex to pull out the first match of a sequence of numbers of any length. The regex will look something like "^\d+" - starts with any number of decimal digits.
Instead of using substring, you should use Split function.
var words = phrase.Split(new string[] {" | "},
StringSplitOptions.RemoveEmptyEntries);
var number = word[0];