Olhado_ 发表于 2022-7-6 11:49:44

LISP: Read a character from st

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.

Lee Mac 发表于 2022-7-6 12:13:23

Certainly,
 
Look into functions:vl-string-position, vl-string-search, substr

devitg 发表于 2022-7-6 12:21:57

Could be (wcmatch string pattern)
You can use wildcardchar like
(setq Pattern ";*")
It will return Tif the line start with [;]

Olhado_ 发表于 2022-7-6 12:31:49

Thanks for the help. I will be looking into these.

ollie 发表于 2022-7-6 12:49:43

you could use
 
 

(if(eq ";" (substr str 1 1)) (princ (strcat "\n" str)))

fixo 发表于 2022-7-6 12:55:47

 
Here is VB.NET way
 

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'~
页: [1]
查看完整版本: LISP: Read a character from st