【问题标题】:String Splitting in Foxpro Visual 9Foxpro Visual 9 中的字符串拆分
【发布时间】:2021-01-12 21:33:02
【问题描述】:

我有一列用逗号分隔的字符串。

示例:城市、邮政编码

我想创建一个仅包含城市的列,所以逗号之前的所有内容。

其他人是如何做到这一点的?我知道使用 Foxpro,您通常可以通过多种方式完成相同的任务。任何帮助将不胜感激。

EDIT: SOLUTION

GETWORDNUM(FIELD,1,",")

这可以在 FIELD 列中的逗号前给出文本字符串。

【问题讨论】:

    标签: visual-foxpro foxpro


    【解决方案1】:

    最简单的方法是使用STREXTRACT()。即:

    lcColumnData = "City, Zipcode"
    
    ? STREXTRACT(m.lcColumnData, "",",")
    

    【讨论】:

      【解决方案2】:
      STORE ALINES(aCZ, "Atlanta, 30301", ",") TO iCZ
      
      City = aCZ[1]
      ZipCode = aCZ[2]
      
      ?City
      ?ZipCode
      

      【讨论】:

      • 口头解释通常很有帮助
      【解决方案3】:

      试试这个:

      str = "City, Zipcode"
      
      *initialize the column value leftcol
      leftcol = ''   
      *find comma position
      pos = At(',', str)
      Do Case
        Case pos > 1 
          * there is a comma and something before that. take everything before that pos
          leftcol = Left(str, pos-1)
      
        Case pos = 1
          * first char is comma
          leftcol = ''
      
        Otherwise
          *there is no comma. take the whole string
          leftcol = str
      EndCase
      

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多