Olhado_ Posted January 19, 2010 Posted January 19, 2010 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. Quote
Lee Mac Posted January 19, 2010 Posted January 19, 2010 Certainly, Look into functions: vl-string-position, vl-string-search, substr Quote
devitg Posted January 19, 2010 Posted January 19, 2010 Could be (wcmatch string pattern) You can use wildcard char like (setq Pattern ";*") It will return T if the line start with [;] Quote
Olhado_ Posted January 20, 2010 Author Posted January 20, 2010 Thanks for the help. I will be looking into these. Quote
ollie Posted January 23, 2010 Posted January 23, 2010 you could use (if(eq ";" (substr str 1 1)) (princ (strcat "\n" str)) ) Quote
fixo Posted January 24, 2010 Posted January 24, 2010 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. Here is VB.NET way Imports System.IO Imports System.Text ........................... Sub try() Dim strAppend As String = "This string is for appending" Dim strFind As String = ";" Dim strLine As String Dim carret As String = Environment.NewLine Dim sb As StringBuilder = New StringBuilder Dim path As String = "C:\MyTextFile.txt" Dim sr As System.IO.StreamReader = New System.IO.StreamReader(path) Using sr If System.IO.File.Exists(path) = True Then sr = System.IO.File.OpenText(path) Do While sr.Peek <> -1 strLine = sr.ReadLine() If strLine.Contains(strFind) Then sb.Append(strAppend & carret & strLine & carret) Else sb.Append(strLine & carret) End If Loop Else Return End If sr.Close() End Using Using sw As System.IO.StreamWriter = New StreamWriter(path) sw.Write(sb.ToString()) End Using End Sub ~'J'~ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.