
-----------------------------------
Synix
Thu Nov 13, 2008 10:59 am

String Manipulation :D
-----------------------------------
Hey guys!

Before you ask, yes I did read the tutorial on string manipulation but it didn't answer my question...

Here's my program so far...

var num, size, pos, count, l : int
var pattern, newpattern, word, newword2 : string
put "Menu"
put "1. Count a pattern"
put "2. Eliminate a pattern"
put "3. Substitute a pattern"
put "4. Exit"
get num
if num = 1
        then
    count := 0
    cls
    put "Enter the single letter pattern you want to count"
    get pattern
    put "Enter a word containing the pattern"
    get word
    size := length (pattern)
    loop
        pos := index (word, pattern)
        exit when pos = 0
        count := count + 1
        word := word (pos + size .. *)
    end loop
    put "The number of occurences is: ", count
elsif num = 2
        then
        cls
    put "Enter the pattern you would like to eliminate"
    get pattern
    put "Enter the word in which you would like to eliminate a pattern from"
    get word
    var newword := ""
    var i : int
    size := length (pattern)
    loop
        pos := index (word, pattern)
        exit when pos = 0
        word := word (1 .. pos - 1) + word (pos + size .. *)
    end loop
    put "Here is the word without the pattern: ", word
elsif num = 3
        then
        cls
    loop
        put "Enter the word you want to replace a pattern in"
        get word
        put "Enter the pattern you would like to search for within the word"
        get pattern
        put "Enter the pattern you would like to replace the old pattern with within the word"
        get newpattern
        loop
        word := word (1 .. index (word, pattern) - 1) + newpattern + word (index (word, pattern) + 1 .. *)
        exit when 
        end loop
        put word
    end loop
elsif num = 4
        then
    put "Go 