乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 75|回复: 5

[编程交流] LISP: Read a character from st

[复制链接]

19

主题

44

帖子

25

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
95
发表于 2022-7-6 11:49:44 | 显示全部楼层 |阅读模式
Is there a current command to read a character from a string?
 
I am asking because I have a program that reads a TXT file I created; but I would like to put a few lines of comments at the beginning. I was thinking about starting it with a semicolon (typical) and then checking for it with my code.
 
I suppose I could try and test my .NET abilities and make a LISP function; but I wanted to check if there was an easier way first.
 
Can I check for a particular character?
 
Thanks.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:13:23 | 显示全部楼层
Certainly,
 
Look into functions:  vl-string-position, vl-string-search, substr
回复

使用道具 举报

32

主题

430

帖子

423

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
150
发表于 2022-7-6 12:21:57 | 显示全部楼层
Could be (wcmatch string pattern)
You can use wildcard  char like
(setq Pattern ";*")
It will return T  if the line start with [;]
回复

使用道具 举报

19

主题

44

帖子

25

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
95
发表于 2022-7-6 12:31:49 | 显示全部楼层
Thanks for the help. I will be looking into these.
回复

使用道具 举报

37

主题

125

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
190
发表于 2022-7-6 12:49:43 | 显示全部楼层
you could use
 
 
  1. (if(eq ";" (substr str 1 1)) (princ (strcat "\n" str)))
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:55:47 | 显示全部楼层
 
Here is VB.NET way
 
  1. Imports System.IOImports System.Text...........................Sub try()Dim strAppend As String = "This string is for appending"Dim strFind As String = ";"Dim strLine As StringDim carret As String = Environment.NewLineDim sb As StringBuilder = New StringBuilderDim path As String = "C:\MyTextFile.txt"Dim sr As System.IO.StreamReader = New System.IO.StreamReader(path)Using srIf System.IO.File.Exists(path) = True Thensr = System.IO.File.OpenText(path)Do While sr.Peek  -1strLine = sr.ReadLine()If strLine.Contains(strFind) Thensb.Append(strAppend & carret & strLine & carret)Elsesb.Append(strLine & carret)End IfLoopElseReturnEnd Ifsr.Close()End UsingUsing sw As System.IO.StreamWriter = New StreamWriter(path)sw.Write(sb.ToString())End UsingEnd Sub
 
~'J'~
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 10:07 , Processed in 0.513822 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表