Remove Quotes From String

A Delphi function that will remove enclosing and double quotes from quoted text, useful for reading CSV data.

Using RemoveQuotes:

Parameters:

S: A string value containing the quoted text.

QuoteChar: The character that is to be treated as the quoted text.

Return Value:

This function will return a string value containing the input text with double and enclosing quote characters removed.

Example:

 

Is String An Anagram?

A Delphi function that determines if a group of letters contain an anagram of specified text.

 

Using IsAnagram:

This function was written to locate words from a dictionary, that could be used in a simple anagram word game. Given a series of letters, the function would test each word from the dictionary one at a time to determine if that word could be a valid anagram made up from those letters.

Parameters:

Letters: A string value containing the letters to be used in the anagram. (Think scrabble tiles)

Text: The text to be checked against letters. (The word to be played in scrabble)

Exact: Are we searching for a perfect anagram, or a partial one? (ie, some tiles left over)

Return Value:

If Exact is True, the function will return True if both Letters and Text are a perfect anagram.

If Exact is False, the function will return True if Text can be made using all or some of the characters in Letters.

Example:

 

Is Credit Card Number Valid?

A Delphi function that will determine if a credit card number passes the credit card number mod 10 test.

Note: This function also uses ReverseStr

Using IsValidCreditCardNumber:

Parameters:

CardNumber: A string value containing the candidate credit card number

Return Value:

If value passed the credit card mod 10 check, the function returns True, if the value fails the check, the function returns False.

If the function returns True, it does not mean the number is a real credit card, this function should only be used to check for a data entry error – not to authorise a sale!

Example:

 

Is String In Array Function

A Delphi function that returns the index of a string from an array of strings.

Using StrInArray:

Parameters:

Str: A string value containing the text that is to be located within the array.

A: An array containing the string values that are to be searched.

Return Value:

If the string is found StrInArray will return an integer value containing the position of the first occurance of that value in the array.

If the string is not found, the function will return a value of -1.

Example:

Great Tip!

Delphi does not allow case statements using string values, which is a bit of a pain sometimes. To perform a case statement on a string try this:

 

Reverse String Function

A simple Delphi implementation of a function to reverse string

Using ReverseStr:

Parameters:

Str: A string value that is to be reversed.

Return Value:

This function will return a string value containing the reversed text.

Example:

 

Strip HTML Tags Function

A Delphi function to remove all HTML / XML type tags from a string of text.

Using StripTags:

Parameters:

S: A string value containing the HTML / XML type tags that are to be removed.

Return Value:

This function will return a string value conatining the value of S with any tags removed.

Example: