├── StringFunctions.bas ├── LICENSE └── README.md /StringFunctions.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todar/VBA-Strings/HEAD/StringFunctions.bas -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Robert Todar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VBA String Functions 2 | A library of String functions to make life easier! =) 3 | 4 | Buy Me A Coffee 5 | 6 | ## References 7 | | Reference | Object | 8 | | ------------------------------------------ | -------------------- | 9 | | Microsoft Scripting Runtime | Scripting.Dictionary | 10 | | Microsoft VBScript Regular Expressions 5.5 | RegExp, Match | 11 | 12 | ## Public Funtions 13 | 14 | | Function | Description | 15 | | ------------------- | ---------------------------------------------------------------------------------------- | 16 | | StringSimilarity | This returns a percentage of how similar two strings are using the levenshtein formula. | 17 | | LevenshteinDistance | The distance between two sequences of words. | 18 | | Inject | Returns a new cloned string that replaced special {keys} with its associated pair value. | 19 | | Truncate | Create a max lenght of string and return it with extension. | 20 | | StringBetween | Find string between two words. | 21 | | StringPadding | Returns a string with the proper padding on either side. | 22 | | ToString | Reads any value or object in VBA and returns it in string formatting. | 23 | 24 | ## Example Usage 25 | 26 | ```vb 27 | '/** 28 | ' * Examples of various functions. 29 | ' * 30 | ' * @author Robert Todar 31 | ' * @licence MIT 32 | ' */ 33 | Private Sub testsForStringFunctions() 34 | Debug.Print StringSimilarity("Test", "Tester") '~> 66.6666666666667 35 | Debug.Print LevenshteinDistance("Test", "Tester") '~> 2 36 | Debug.Print Truncate("This is a long sentence", 10) '~> "This is..." 37 | Debug.Print StringBetween("Robert Paul Todar", "Robert", "Todar") '~> "Paul" 38 | Debug.Print StringPadding("1001", 6, "0", True) '~> "100100" 39 | Debug.Print Inject("Hello,\nMy name is {Name} and I am {Age}!", "Robert", 31) 40 | '~> Hello, 41 | '~> My name is Robert and I am 30! 42 | 43 | Debug.Print ToString(Array(1, 2, 3, 4)) '~> [1, 2, 3, 4] 44 | End Sub 45 | ``` 46 | --------------------------------------------------------------------------------