Computer Science Canada

String Manipulation Module

Author:  Aange10 [ Sat Jun 02, 2012 10:41 pm ]
Post subject:  String Manipulation Module

Features

Here are some common function I use in almost any program with string manipulation, so I figured I'd put it all in one module.

So here are the functions:
- removeTrailingEnter: This function will remove the enter that is at the end of all input you get when reading from a file. This is extremely helpful if you are directly using the information you are retrieving from the file, or if you plan to format the data (the enter at the end may cause unnecessary trouble, especially to somebody who forgets about it being there.)

- removeOuterSpaces: This is another function I almost always need to use while formatting data, because I don't want spaces to mess up the input.

- bulletProofGet: Probably the most useful function. This function will make sure that your program will not crash from invalid input. It is a lot of work to do this in every program, so this function is definitely the highlight of the module. Not to mention this is needed for every program that is meant to take input via get.

- getStringPos: This is probably one of the most common functions used. It will take in a string and a substring, and will tell you what position the substring occurs in the string.

- isIn: Is a simple boolean function that will tell you if a substring is contained within a string.

- replace: Our final function, replace will take in a string, a "replace what" string, and a "replace with" string, and replace the "replace what" string with the "replace with" string in every occurrence.

How it Works

Meh, just simple string manipulation.
Syntax


- fcn removeTrailingEnter (input : string) : string

- fcn removeOuterSpaces (input_ : string) : string

- fcn bulletProofGet (typeToGet : string) : string

- fcn getStringPos (line, toFind : string, startingPosition : int) : int

- fcn isIn (line, toFind : string) : boolean

- fcn replace (sentance_, substring, replaceWith : string) : string

The Module

Working Example


Both are attatched.

Author:  Raknarg [ Sun Jun 03, 2012 5:19 pm ]
Post subject:  RE:String Manipulation Module

Im pretty sure the index function already exists (same thing as your isIn function, but mroe detailed)

Author:  Aange10 [ Sun Jun 03, 2012 7:26 pm ]
Post subject:  Re: RE:String Manipulation Module

Raknarg @ 3/6/2012, 4:19 pm wrote:
Im pretty sure the index function already exists (same thing as your isIn function, but mroe detailed)


Where?

Author:  Dreadnought [ Sun Jun 03, 2012 8:59 pm ]
Post subject:  Re: String Manipulation Module

index

Author:  Aange10 [ Sun Jun 03, 2012 9:02 pm ]
Post subject:  RE:String Manipulation Module

Oh, didn't know Turing had it. That's useful; anyways, this module will still be put to use

Author:  Aange10 [ Sun Jun 03, 2012 10:15 pm ]
Post subject:  RE:String Manipulation Module

Except, that it can't find an occurance of a substring in different spots.


: