【共享】切分字符串的一段源码(页 1) - ENVI/IDL - 研学论坛 研学|学术|科...
【共享】切分字符串的一段源码
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
;+
; NAME:
; SPLIT
;
; IDENT:
; $Id: split_hdf.pro,v 1.1 2003/02/14 20:20:07 glennh Exp $
;
; PURPOSE:
; Just like perl. Splits a string into an array of strings.
;
; AUTHOR:
; Ed Santiago
;
; CALLING SEQUENCE:
; stringarr = split(delimiter, string)
;
; INPUTS:
; delimiter -- character to split on
; string -- string to split
;
; OUTPUTS:
; an array of strings
;
; SIDE EFFECTS:
;
; EXAMPLE:
; IDL> x=split(',', 'this,is,a,test')
; IDL> print, N_Elements(x), x
; 4 this is a test
;
;-
FUNCTION split, delimiter, string; Just like perl
arr = [ 'x' ] ; sigh
len = strlen(string)
lastpos = 0
WHILE lastpos LT len DO BEGIN
pos = STRPOS(string, delimiter, lastpos)
IF pos EQ -1 THEN pos = len
arr = [ arr, STRMID(string, lastpos, pos-lastpos) ]
; Collapse multiple spaces into one
IF delimiter EQ ' ' THEN WHILE StrMid(string,pos+1,1) EQ ' ' DO pos=pos+1
lastpos = pos+1
ENDWHILE
; Always guaranteed at least one hit, unless string is null
RETURN, arr[1:*]
END
mingxian 发表于 2006-1-10 12:24
Re:【共享】切分字符串的一段源码
用法,比如
strTime = '2006/01/10'
sTime = split('/',strTime)
sTime就是['2006','01','10']
hexiaoyao 发表于 2006-1-31 12:16
Re:【共享】切分字符串的一段源码
heihei我想利用Reads来读取字符串更好一点
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。