打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【共享】切分字符串的一段源码(页 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来读取字符串更好一点
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ABB机器人如何解析机器视觉主机发送的坐标数据
汉字转换为拼音的宏
java版本的escape和unescape函数
自己收集的几个比较实用的Delphi字符串函数(LeftStr,MidStr,RightStr,Reverse,LastPos)
split 函数
VBA基础入门(46)Split与Join
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服