Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Validation and fixing of starting or ending strings

Author
Message
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Aug 2015 13:25 Edited at: 22nd Aug 2015 13:28
The following functions determine what to return depending on whether a string starts with something, or ends with something.

The first pair of functions return true if the string, starts or ends a series of characters. An additional parameter allows you to change the character case mode. Setting it to 1 will require the string to be exact; otherwise lower or upper cased versions of the same character will match. EndsWith$("My name is Sam", "Sam", 0) returns true; EndsWith$("1234", "4", 0) returns true; StartsWith$("1234","4",0) returns false.

The second pair of functions return a new string ending or starting with a required pattern, whether or not the pattern is not already there. For example: RequireSuffix$("file", ".x", ".dbo") returns 'file.x' because the first parameter does not already end with the required suffix. The function provides an additional default parameter for using a dynamic expression to determine the extension. RequireSuffix$("file", GetRequiredFileExtension(), ".txt") will suffix the dynamic extension provided by the anonymous function GetRequiredFileExtension(), if the function returns no suffix, the default suffix '.txt' is appended instead. RequirePrefix$() is the reverse version of RequireSuffix$() which appends at the start instead of the end, therefore RequirePrefix$("file.txt","c:\program files\game\, "") will return "c:\program files\game\file.txt".

Matrix1


Vanilla


Login to post a reply

Server time is: 2024-11-21 15:45:59
Your offset time is: 2024-11-21 15:45:59