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. Certainly,
Look into functions:vl-string-position, vl-string-search, substr Could be (wcmatch string pattern)
You can use wildcardchar like
(setq Pattern ";*")
It will return Tif the line start with [;] Thanks for the help. I will be looking into these. you could use
(if(eq ";" (substr str 1 1)) (princ (strcat "\n" str)))
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]