我需要从字符串
中获取子字符串所以我需要"在分配FD分析员后需要输入。用户未经授权。"
出于此:
在System.Reflection.MethodBase.Invoke(Object obj,Object []参数) at DOCSIDE.Web.Util.ExecuteMethod(Object o,String method,Object [] arguments,String buildNumber)in C:\ Software \ DOCSIDEFINAL \ DOCSIDE \ Main \ DOCSIDEBusinessLogic \ Web \ Util.cs:line 247
+++ DOCSIDE Sproc - updateTrkRecord Line - 2203 [@@ Error = 50000]在分配FD分析员后需要输入类型。用户未经授权。 在DOCSIDE.Web.WebMethods.UpdateTrkRecord(TrkRecordCUD t,TrkRecordAction a)中的C:\ Software \ DOCSIDEFINAL \ DOCSIDE \ Main \ Web.cs:第255行
答案 0 :(得分:0)
如果您的错误消息始终相同,则可以使用indexOf和substring
示例代码
<script>
function test() {
var str = 'at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at DOCSIDE.Web.Util.ExecuteMethod(Object o, String method, Object[] arguments, String buildNumber) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\DOCSIDEBusinessLogic\Web\Util.cs:line 247+++ DOCSIDE Sproc - updateTrkRecord Line - 2203 [@@Error=50000] Type is required after FD analyst has been assigned. User is not authorized. at DOCSIDE.Web.WebMethods.UpdateTrkRecord(TrkRecordCUD t, TrkRecordAction a) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\Web.cs:line 255';
var start = str.indexOf("[@@Error=50000]");
var end = str.indexOf(" at DOCSIDE.Web.WebMethods");
var get = str.substring(start + 16, end);
document.write(get);
}
</script>
第2版
如果您知道错误50000始终是相同的
<script>
function test() {
var str = 'at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at DOCSIDE.Web.Util.ExecuteMethod(Object o, String method, Object[] arguments, String buildNumber) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\DOCSIDEBusinessLogic\Web\Util.cs:line 247+++ DOCSIDE Sproc - updateTrkRecord Line - 2203 [@@Error=50000] Type is required after FD analyst has been assigned. User is not authorized. at DOCSIDE.Web.WebMethods.UpdateTrkRecord(TrkRecordCUD t, TrkRecordAction a) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\Web.cs:line 255';
//Check if error is 50000
if( str.indexOf('Error=50000') >= 0){
var start = str.indexOf("[@@Error=50000]");
var end = str.indexOf(" at DOCSIDE.Web.WebMethods");
var get = str.substring(start + 16, end);
document.write(get);
}
}
</script>
答案 1 :(得分:0)
简单:关心这是ES6语法
let str=`
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at DOCSIDE.Web.Util.ExecuteMethod(Object o, String method, Object[] arguments, String buildNumber) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\DOCSIDEBusinessLogic\Web\Util.cs:line 247
+++ DOCSIDE Sproc - updateTrkRecord Line - 2203 [@@Error=50000] Type is required after FD analyst has been assigned. User is not authorized. at DOCSIDE.Web.WebMethods.UpdateTrkRecord(TrkRecordCUD t, TrkRecordAction a) in C:\Software\DOCSIDEFINAL\DOCSIDE\Main\Web.cs:line 255`;
console.log(str.includes("Type is required after FD analyst has been assigned. User is not authorized."));
&#13;