當我嘗試通過使用正則運算式匹配將字串運算式分成兩個來將第一個 int 值等于 short 型別的物件時出現錯誤。
我的代碼
var splitedResolution = sub.ResolutionValue.Split('*');
var resolutionwidht = Regex.Match(splitedResolution[0], @"\b\d \.?\d?\b");
resolutionReportsub.Width =Convert.ToInt16(resolutionwidht);
uj5u.com熱心網友回復:
-Match方法回傳一個Match-object。該物件還有一個Success-property 來確定字串是否與您的模式匹配。
為了獲得實際匹配的字串,請使用theMatchObject.Value:
var splitedResolution = sub.ResolutionValue.Split('*');
var resolutionwidht = Regex.Match(splitedResolution[0], @"\b\d \.?\d?\b");
resolutionReportsub.Width =Convert.ToInt16(resolutionwidht.Value);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/465514.html
