如何使用angularjs拆分字符串和表单数组 [英] How to split string and form array using angularjs
本文介绍了如何使用angularjs拆分字符串和表单数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串值,如果是,"或.",则需要拆分字符串.存在并且需要形成一个数组.
I have two string values and need to split the string if "," or "." is present and need to form an array.
$scope.welcome = "Welcome to Adityavani facitlity services, please select from the following";
$scope.final = "Thanks for calling. You have registered successfully";
我需要创建一个如下数组:
I need to create an array as below:
$scope.welcome_array = ["Welcome to Adityavani facitlity services", "please select from the following"];
$scope.final_array = ["Thanks for calling", "You have registered successfully"];
推荐答案
$scope = {};
$scope.welcome = "Welcome to Adityavani facitlity services, please select from the following";
$scope.final = "Thanks for calling. You have registered successfully";
$scope.splitSrting=function(splitStr){
var reg=/[,.]\s*/;
return splitStr.split(reg);
}
console.log($scope.splitSrting($scope.welcome));
console.log($scope.splitSrting($scope.final));
这篇关于如何使用angularjs拆分字符串和表单数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文