;============================================================== ;StringToDoubleArray ;============================================================== Function StringToDoubleArray,DblStr,DoubleArray,Count ;用法IDL>Status=StringToDoubleArray(DblStr,DoubleArray,Count) ;DblStr要转换的字符串,字符串可以是'1.23 ,3.4;0.3 E2.2 afd 3er.7 ' ;DoubleArray保存double类型的数组 ;Count总共可以提取多少个double类型的数 ;返回是否成功的标志 ;---------------------------------------------------------------- Count=0 ;---------------------------------------------------------------- ;先对\t处理一下 Stab=STRSPLIT(DblStr, STRING(9b),/EXTRACT) str=STRJOIN(Stab, ' ') Si=STRSPLIT(Str,'[;,: ]',/EXTRACT,/REGEX) ;---------------------------------------------------------------- nn = n_elements(Si) ;---------------------------------------------------------------- if (nn GT 0) then begin DoubleValue=findgen(nn) LineSize=UINDGEN(nn) ;------------------------------------ for n=0L,nn-1 DO BEGIN valid=IsDoubleString(Si[n]) if (valid GT 0) then begin DoubleValue[n]=fix(Si[n],type=5) LineSize[n]=1; endif else begin DoubleValue[n]=0 LineSize[n]=0; endelse endfor ;------------------------------------ count=total(LineSize); index=where(LineSize GT 0) ;------------------------------------ if (count GT 0) then begin DoubleArray=DoubleValue[index] endif ;------------------------------------ return,1 ;------------------------------------ endif else begin return,0 end ;---------------------------------------------------------------- END
IDL中将字符串转为double类型的数组的函数StringToDoubleArray
最新推荐文章于 2021-07-14 22:31:42 发布