Jump to content

LISP: Read a character from string?


Olhado_

Recommended Posts

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.

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...