In the report development process, some requirements may not be implemented through the existing functions, requires two development of developers, taking Finereport as an example, you can use Web page scripting, API interface, etc. for in-depth development and control.
Considering the use of JS script development, here is a brief introduction of how to use JS to manipulate the string, such as how to determine whether the string is empty, the length of the string, replace, find, intercept, or convert the string to other types.
1. Length of the string
1.1 Return string length
Gets the string length that can be used for the string object's Length property. For example :
var txt= "Hello FR"; txt.length; //
It will return 8.
1.2 Null for string
String is empty, that is, the string length is 0, to achieve a null, you can use the following methods:
if (txt.length==0| | txt== " )returntrue; // is empty Else return false; // is not empty
Here, txt.length==0 or txt== "only need to meet one can
2. Substitution of strings
The replace () method of the string Stringobject performs a find-and-replace operation. It looks for substrings in Stringobject that match regexp, and then replaces them with replacement. If RegExp has global flag G, then the Replace () method replaces all matching substrings. Otherwise, it replaces only the first matched substring.
Here is an example of a string substitution :
var txt= "Visit fr!" ; Txt.replace (
The result will return Hello fr!
3. Searching for strings
The search (RegExp) method is used to retrieve the substring specified in the string, and he returns the starting position of the first substring in the stringobject that matches the regexp.
If it is not found, it will return-1.
However, the search method cannot find the global and finds only the first occurrence of the matching string.
4. Interception of strings
We can use the substr (Start,length) method to extract some of the contents of a string.
Where start is the start, fetch a new string of length.
As an example ,
var txt= "Visit fr!" ; Txt.substr (6,2); //
The above results will return FR
The string subscript starts at 0, and if start is negative, it is extracted from the beginning by default.
5. Connection of strings
Multiple strings can be concatenated by the concat (Str1,str2 ...) method of the string
Like what
var str1= "Hello"; var str2= "FR";
The result will return a Hello FR
6. String Type conversions
6.1 Converting a string to a numeric value
You can use the cast directly.
parsefloat (str) if it is converted to a floating-point number
parseint () If converted to an integer type
6.2 Converting a string to an array
You can use the split (separate) method of the string to split the string into arrays.
Separate to filter strings.
Like what
var str1= "I love FR"; var
Web Report Tool Finereport string for JS development