如何编写一个查找文本框里是否含有成对出现的"<"和">".

learn_vb 2000-07-24 08:43:00
如何编写一个查找文本框里是否含有成对出现的"<"和">".能否举个例子还有字符串的扫描函数应什么.
...全文
144 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwin 2000-07-25
  • 打赏
  • 举报
回复
如果你的意思是“<1<2<3<4>5>6>7>”,则使用以下代码:

public function IsEmbedPair(byval strInput as string) as Boolean
dim i as long,n as long
dim s as string

for i=1 to len(strInput)
s=mid(strInput,i,1)

if s="<" then
n=n+1
elseif s=">" then
n=n-1
end if

if n<0 then exit function
next i

if n=0 then IsEmbedPair=true
end function


如果你的意思是只能“d<12>d<2>d<3>s<f>f<f>”,则使用以下代码:

public function IsPair(byval strInput as string) as boolean
dim i as long,n as long
dim s as string

for i=1 to len(strInput)
s=mid(strInput,i,1)

if s="<" then
n=n+1
elseif s=">" then
n=n-1
end if

if n<0 or n>1 then exit function '只有这一句不同
next i

if n=0 then IsEmbedPair=true
end function
Tyro 2000-07-24
  • 打赏
  • 举报
回复
成对出现是什么意思呀?是说"<"和">"的数目一样吗?
wulang 2000-07-24
  • 打赏
  • 举报
回复
同意yanrj,用堆栈
yanrj 2000-07-24
  • 打赏
  • 举报
回复
编写一个算法,可利用一个堆栈,出现一个<堆栈累加1,遇到一个>弹出一个值,看最后堆栈是否为空。也可设置一计数器,初值为0,出现一个<加1,遇到一个>减1,最后计数器为0则成对.

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧