locked
How can i change some word in the text ? RRS feed

  • Question

  • First, my english is poor. i hope my words can be understood.

    For example, I have a file my.txt . Then I have search and get the word "one", how can i change the word "one" to "two". 

    Thursday, March 10, 2011 11:56 AM

Answers

  • Use Shapes.SetText(text, "text")

    ~~AirWaves!!~~
    • Marked as answer by mskimizd Friday, March 11, 2011 9:55 AM
    Thursday, March 10, 2011 4:02 PM

All replies

  • Use Shapes.SetText(text, "text")

    ~~AirWaves!!~~
    • Marked as answer by mskimizd Friday, March 11, 2011 9:55 AM
    Thursday, March 10, 2011 4:02 PM
  • There are two ways you can do this.

    1.
    File.WriteLine(filePath, lineNumber, contents)
    Example
    File.WriteLine("C:/users/kirkkaf/Documents/my.txt", 1, "Two")
    This will write at certain line number in the file.
    2.
    File.WriteContents(filePath, contents)
    Example
    File.WriteLine("C:/users/kirkkaf/Documents/my.txt", "Two")
    This will replace anything in the file.
    Hope this helps.
    Thursday, March 10, 2011 7:58 PM
  • Here is a small sample doing a multiple 'find and replace' on some text, using the SmallBasic Text command.  This assumes that the text is read into SmallBasic first, then some manipulation of the text is carried out, possibly before writing back to a file.  Import JDD202.
    Thursday, March 10, 2011 8:11 PM
  • You mean i can use Shapes.SetText on text? I remember it can only use in graphicswindow.

    Friday, March 11, 2011 10:02 AM
  • Thank you for your answering. I know these two ways.

    but i mean that if i have many words and mang lines in a file . I don't want to replace all the things or certain line, I just want to change one word in certain line.

    anything better ways?

    Friday, March 11, 2011 10:06 AM
  • en~~, I don't understand the last step. How can i import the word which i have changed. I mean put on the position which i get it.
    Friday, March 11, 2011 10:12 AM
  • Yes, you can only use shapes.settext on the graphicswindow. For just changing one word in a certain line, the best idea would be to write the contents into a file, then use File.WriteLine with the new text for the line. After that you just read the file and  write it out onto the textwindow.

    So say you want to write this out onto the textwindow

    Hello, I am advertising these books.
    Call now, and you get all of them
    100% free! Just dial ###-###-####!
    You have 18 seconds

     

    But you then wanted to replace ###-###-#### with your actual phone number. You could use this code:

    line[1]="Hello, I am advertising these books."
    line[2]="Call now, and you get all of them"
    line[3]="100% free! Just dial ###-###-####!"
    line[4]="You have 18 seconds"
    For i = 1 To Array.GetItemCount(line)
        string = TextAppendContents(string, line[i]+Text.GetCharacter(10))
    EndFor
    File.WriteContents("C:\testfile.txt", string)
    File.WriteLine("C:\testfile.txt", 3, "100% free! Just Dial 012-345-6789")
    readcontents = File.ReadContents("C:\testfile.txt")
    TextWindow.WriteLine(readcontents)


    ~~AirWaves!!~~
    Friday, March 11, 2011 7:39 PM