本文收集整理关于vfp如何按行读取字符串的相关议题,使用内容导航快速到达。
内容导航:
Q1:vfp读取编号并进行字符串处理
假设你的VFP是6.0或以下的版本;
假设你的表单中有个名叫〔Search〕按钮,那在该按钮的〔Click〕事件中加上以下代码:
SET DATE TO YMD
SET CENTURY ON
cSearDate = ALLTRIM(ThisForm.Text_Search.Value)
dSearDate = CTOD(cSearDate)
SET SAFETY OFF
SELECT Code, Name, Enrol_Date, SPACE(LEN(Code)*3) AS Tmp_Field FROM Table_A WHERE ENROL_DATE = dSearDate INTO TABLE Tmp_Table
nFoundRecord = RECCOUNT()
cFoundRecord = ALLTRIM(STR(nFoundRecord))
nLast_Code = 0
cLast_Code = ""
cGet_Code = ""
FOR nLoop_01 = 1 TO nFoundRecord
GO nLoop_01、 SCATTER MEMVAR FIELD Code, Tmp_Field
IF nLoop_01 = 1、cGet_Code = ALLTRIM(m.Code) + "~"
cLast_Code = ALLTRIM(m.Code)
nLast_Code = VAL(m.Code)
ELSE
nGet_Code = VAL(m.Code)
IF nLoop_01 = nFoundRecord
IF nGet_Code - 1 = nLast_Code
REPLACE Tmp_Field WITH cLast_Code + "~" + ALLTRIM(m.Code)
ELSE
REPLACE Tmp_Field WITH ALLTRIM(m.Code)
SKIP -1、IF EMPTY(Tmp_Field)
REPLACE Tmp_Field WITH cLast_Code
ENDIF
SKIP 1、ENDIF
ELSE
IF NOT nGet_Code - 1 = nLast_Code
SKIP -1、IF cLast_Code $ cGet_Code
REPLACE Tmp_Field WITH cLast_Code
ELSE
REPLACE Tmp_Field WITH cGet_Code + cLast_Code
ENDIF
SKIP 1、cGet_Code = ALLTRIM(m.Code) + "~"
ENDIF
ENDIF
cLast_Code = ALLTRIM(m.Code)
nLast_Code = VAL(m.Code)
ENDIF
NEXT
cGetTmpStr = ""
FOR nLoop_01 = 1 TO nFoundRecord
GO nLoop_01、 SCATTER MEMVAR FIELD Tmp_Field
IF EMPTY(m.Tmp_Field)
LOOP
ENDIF
IF EMPTY(cGetTmpStr)
cGetTmpStr = ALLTRIM(m.Tmp_Field)
ELSE
cGetTmpStr = cGetTmpStr + ", " + ALLTRIM(m.Tmp_Field)
ENDIF
NEXT
ThisForm.Text_cn.Value = http://127.0.0.1/yijitao/cFoundRecord
ThisForm.Text_bz.Value = http://127.0.0.1/yijitao/cGetTmpStr
ThisForm.Refresh
USE
ERASE Tmp_Table.DBF
SET SAFETY ON
假设你的VFP是7.0或以上的版本;
假设你的表单中有个名叫〔Search〕按钮,那在该按钮的〔Click〕事件中加上以下代码:
SET DATE TO YMD
SET CENTURY ON
cSearDate = ALLTRIM(ThisForm.Text_Search.Value)
dSearDate = CTOD(cSearDate)
SELECT Code, Name, Enrol_Date, SPACE(LEN(Code)*3) AS Tmp_Field FROM Table_A WHERE ENROL_DATE = dSearDate INTO CURSOR Tmp_Table READWRITE
nFoundRecord = RECCOUNT()
cFoundRecord = ALLTRIM(STR(nFoundRecord))
nLast_Code = 0
cLast_Code = ""
cGet_Code = ""
FOR nLoop_01 = 1 TO nFoundRecord
GO nLoop_01、 SCATTER MEMVAR FIELD Code, Tmp_Field
IF nLoop_01 = 1、cGet_Code = ALLTRIM(m.Code) + "~"
cLast_Code = ALLTRIM(m.Code)
nLast_Code = VAL(m.Code)
ELSE
nGet_Code = VAL(m.Code)
IF nLoop_01 = nFoundRecord
IF nGet_Code - 1 = nLast_Code
REPLACE Tmp_Field WITH cLast_Code + "~" + ALLTRIM(m.Code)
ELSE
REPLACE Tmp_Field WITH ALLTRIM(m.Code)
SKIP -1、IF EMPTY(Tmp_Field)
REPLACE Tmp_Field WITH cLast_Code
ENDIF
SKIP 1、ENDIF
ELSE
IF NOT nGet_Code - 1 = nLast_Code
SKIP -1、IF cLast_Code $ cGet_Code
REPLACE Tmp_Field WITH cLast_Code
ELSE
REPLACE Tmp_Field WITH cGet_Code + cLast_Code
ENDIF
SKIP 1、cGet_Code = ALLTRIM(m.Code) + "~"
ENDIF
ENDIF
cLast_Code = ALLTRIM(m.Code)
nLast_Code = VAL(m.Code)
ENDIF
NEXT
cGetTmpStr = ""
FOR nLoop_01 = 1 TO nFoundRecord
GO nLoop_01、 SCATTER MEMVAR FIELD Tmp_Field
IF EMPTY(m.Tmp_Field)
LOOP
ENDIF
IF EMPTY(cGetTmpStr)
cGetTmpStr = ALLTRIM(m.Tmp_Field)
ELSE
cGetTmpStr = cGetTmpStr + ", " + ALLTRIM(m.Tmp_Field)
ENDIF
NEXT
ThisForm.Text_cn.Value = http://127.0.0.1/yijitao/cFoundRecord
ThisForm.Text_bz.Value = http://127.0.0.1/yijitao/cGetTmpStr
ThisForm.Refresh
=================
Fox_Layman 注:
本人在好几个版本中测试通过。
Q2:vfp字符串的连接
根据楼上的回答,我补充说明下:
FOR I=1 TO 3、??"A"
ENDFOR
结果显示:AAA
FOR I=1 TO 3、?"A"
ENDFOR
结果显示:
A
A
A
晕死,按你这个VFP熟悉程度,我还真没法跟你讲。字符串相连接可用+号,字符串表达式要用引号引起来,引号可以用“”,也可以用‘’。
Q3:vfp中如何获得两字符之间的字符串?
如果文本字段的格式是规范的,可以用取子字符串命令:
Substr(a,n1[,n2]),
n1从左开始的起始字符序号,
n2是所含字符个数,可以省略,如果省略则到最后。
但一般不规范。
如果文本字段的格式是不规范的,可以先用定位子串位置命令,算出起始位置和字符长度,再用上述的取子字符串命令。定位子串位置命令:
At(a,c2[,n])
C2为要定位的子串,例如“市”、“区”、"县","乡"、"镇"、"旗"等。
n为第几次,可省略,默认值为1。
Q4:VFP中如何在字符串中取数字串?
substr() 函数
如:substr("计算机科学技术",7,4)结果为 "科学"