Jump to content
Sign in to follow this  

_StringStartsWith, _StringEndsWith

Recommended Posts


These two functions can be found in the string class in C#. I found them very useful for parsing things like constants, single line(and multiline) comments, etc. I noticed nobody has written these two functions yet, so I decided to. These two functions simply check if the input string starts with the search string and can also check if the input string ends with the search string.

You can download the main header file here:


and an example for each of the functions here:



Also, here is a "real world" example of analysing basic C styled code using these functions.

#include "StringStart.au3"

Local $sCode = "#include <iostream> " & @CRLF & "#include <windows.h>" & @CRLF & @CRLF & "int main(int argc, char* argv[])" & @CRLF & "{" & @CRLF
$sCode &= "    //This is a comment," & @CRLF & "    //that runs onto another line, that is also a comment." & @CRLF
$sCode &= "}"

Local $aResults = _ParseLines($sCode)

MsgBox(0, "Results:", "Bracket Lines: " & $aResults[0] & @CRLF & "Comment Lines: " & $aResults[1])

Func _ParseLines($szData)
    Local $aiCounts[2] = [0, 0]
    Local $asLines = StringSplit($szData, @CRLF)
    For $i =  1 to $asLines[0]
        $asLines[$i] = StringStripWS($asLines[$i], BitOR(1, 2))
        if ( (_StringStartsWith($asLines[$i], "{") or _StringStartsWith($asLines[$i], "}")) and (_StringEndsWith($asLines[$i], "{") or _StringEndsWith($asLines[$i], "}")) ) Then
            $aiCounts[0] += 1
        Elseif (_StringStartsWith($asLines[$i], "//")) Then
            $aiCounts[1] += 1
    return $aiCounts
Edited by chris95219

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.