C++ Builder has a lot of specific methods in its SysUtils library that are included in the VCL and FMX libraries. Some of these are grouped as Path Manipulation Routines that allow users to edit, extract, get and set drive name, directory name, file name, and file extensions. These methods are combined in the Vcl.FileCtrl, System.IOUtils, System.SysUtils libraries. These methods are easy to use and easy to get or set file path strings in that operating system. They can be used with other component properties like FileName property of OpenDialog, SaveDialog components. We can also check drives, files, or directories to see if they exist or not on a given path. We can also get some specific directory locations like the “Current Directory”.
In this post, you will learn how to add a trailing backslash to a path string, how to remove a trailing backslash from the end of a path string, the C++ ExcludeTrailingBackslash method and the IncludeTrailingBackslash method, the difference between the ExcludeTrailingBackslash and the ExcludeTrailingPathDelimiter methods, and the difference between the IncludeTrailingBackslash and the IncludeTrailingPath.
By learning how to include or exclude trailing backlashes Windows operating system. It will help you to easily build C++ applications using the C++ IDE.
Table of Contents
What is the C++ ExcludeTrailingBackslash method ?
The ExcludeTrailingBackslash Method (System.SysUtils.ExcludeTrailingBackslash) is a SysUtils Method that returns a pathname without a trailing delimiter. This method is included for backward compatibility only. The System.SysUtils.ExcludeTrailingPathDelimiter should be used instead. ExcludeTrailingBackslash returns a UnicodeString, with the trailing path delimiter (PathDelim, ‘\’ on Windows, ‘/’ on Linux, macOS, and mobile platforms) removed. Note that ExcludeTrailingBackslash works with multibyte character sets (MBCS).
What is the syntax of the ExcludeTrailingBackslash method?
Here is the ExcludeTrailingBackslash Method:
1 2 3 |
UnicodeString __fastcall ExcludeTrailingBackslash(const System::UnicodeString S); // overload |
What is the C++ IncludeTrailingBackslash method ?
The IncludeTrailingBackslash Method (System.SysUtils.IncludeTrailingBackslash) is a SysUtils Method. It ensures that a path name ends with a delimiter. This method is included for backward compatibility only. System.SysUtils.IncludeTrailingPathDelimiter should be used instead. System.SysUtils.IncludeTrailingBackslash. IncludeTrailingBackslash ensures that a path name ends with the trailing path delimiter (PathDelim, ‘\’ on Windows, ‘/’ otherwise). Note that IncludeTrailingBackslash works with multibyte character sets.
What is the syntax of IncludeTrailingBackslash method ?
Here is the ExcludeTrailingBackslash Method:
1 2 3 |
UnicodeString __fastcall IncludeTrailingBackslash(const System::UnicodeString S); // overload |
What is a simple example of using the C++ ExcludeTrailingBackslash and IncludeTrailingBackslash methods?
ExcludeTrailingBackslash and IncludeTrailingBackslash methods both return UnicodeString. We can use them as given below,
1 2 3 4 5 6 7 |
String path1 = IncludeTrailingBackslash( L"D:\\MyFolder" ); ShowMessage(path1); String path2 = ExcludeTrailingBackslash( L"D:\\MyFolder\\" ); ShowMessage(path2); |
and the outputs will be as follows respectively,
1 2 3 |
D:\MyFolder\ |
and,
1 2 3 |
D:\MyFolder |
Here is a full example of how to use the C++ ExcludeTrailingBackslash and IncludeTrailingBackslash methods
Here is the full C++ Builder VCL example,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { String path1, path2, path; path1 = L"D:\\MyFolder"; path2 = L"D:\\MyFolder\\"; Memo1->Lines->Add( "Path1: " + path1 ); path = IncludeTrailingBackslash( path1 ); Memo1->Lines->Add( "IncludeTrailingBackslash: " + path ); Memo1->Lines->Add( "Path1: " + path2 ) ; path = ExcludeTrailingBackslash( path2 ); Memo1->Lines->Add( "IncludeTrailingBackslash: " + path ); } |
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition