In case is using component is often used in text display some information, and sometimes need some format of the information is processing, such as display mobile phone number when we may want to only show the beginning and the tail, such as in the demo and to hide among the four, said today about how to such a formatted string processing.

1. Data binding

First of all, a one-dimensional array is built in the demo to store several mobile phone numbers, and then the circular creation is carried out using this one-bit array as the data source. The text component under the for container is data-bound, and some functions and methods are added after the current data 1. This is all JavaScript function methods and syntax. (To use JS methods, you need to use data-bound schemas.)

A regular expression is a logical formula used to manipulate strings. It uses predefined characters and the combination of these characters to form a “regular string”. The “regular string” is used to filter strings. Regular expressions are powerful in their own right, but it takes a lot of practice to become particularly proficient with them. There is a saying that when you solve a problem with regular expressions, you now have two problems. Here is a brief introduction to the code meaning in the demo, interested friends can go to learn regular expressions in detail. The current datatone is a string object, and the replace() method is used here, which can be interpreted as the double quotation marks following the “, “in parentheses replacing the content between two”/” s. The g means to perform a global match, that is, to look for all matches rather than stop after the first match is found. ^(\d{3}), \d{4}, (\d{4})“Matches the position at the end of the input string, with \d representing the number searched and {3} representing the number of digits searched. So this is the first three digits, the middle four digits and the end four digits. $1 stands for (\d{3}) and $2 stands for (\d{4}). This is the use of the regular expression capture group, the capture group is the regular expression of the content of the neutron expression match, stored in memory numbered or explicitly named group for later reference. Only the parts enclosed in parentheses can be captured (details of the capture group numbering and naming rules and references are available online). In this way, the first three parts and the last four parts are retained, and the middle part is changed to ****, and the final result is spliced together.

An easier way to do this is to use substr(), which takes a substring from the original string. The method takes only two numeric arguments, the starting position followed by the length of the substring. Please refer to the following figure for details.

There is also an alternative method, slice(), which is different from substr() in that substr() parameters specify the start position and length, while slice() parameters specify the start and end positions.

There is also a substring() method similar to the slice() method. And slice () method is different though he parameter is also starting and ending coordinates, but he is not to accept negative number as a parameter, and if not careful will terminate coordinates to fill even smaller than the starting coordinates, then the method of two parameters will be change before execution, if the starting coordinates and end coordinates are equal, then it returns an empty string.

A more common method to share is the split() method. For example, if the submission time in the database is “2020-03-16 15:37:36”, we may only want to show the date of year, month and year in the foreground display, leaving out minutes and seconds.

Finally, add a case conversion method, it is also very simple to use, in order to convert lowercase for example. This data binding converts all lowercase letters in text variables to uppercase letters.

There are many different ways to format strings, and you can explore new ways for yourself. Ivx itself also maintains the interface that can be used jointly with some function methods, and has specialized function components, which are still very convenient for handling some small details. The more comprehensive the knowledge is really good!