Is there a C # equivalent for FoxPro addbs ()?

In Visual FoxPro. There is an addbs () function with which you pass the string.

If there is no backslash at the end of the (trimmed) line, it will add it. If there is a backslash, it will return the trimmed string.

lcString = 'C:\Example' lcNewString = addbs(lcString) ?lcNewString Output: C:\Example\ 

Is there an equivalent function in C #?

+4
source share
5 answers

Maybe the Path class can help you here? For example, the comb () method.

+5
source

As others have said, you probably want to use Path.Combine

However, you can easily create your own method for this:

 public string AddBS(string value) { return value.EndsWith("\\") ? value : value + "\\"; } 

To make it more general, I would suggest making an extension, for example:

 public static class StringExtensions { public static string AddSuffix(this string value, string suffix) { return value.EndsWith(suffix) ? value : value + suffix; } } 
+2
source

There is a free " Visual FoxPro Toolkit for .NET " that has C # and VB libraries that bring many of FoxPro's features to .Net.

http://foxcentral.net/microsoft/vfptoolkitnet.htm

The Visual FoxPro Toolkit for .NET is a class library with over 225 Visual FoxPro features for use with any .NET language. The included VFPToolkitNET.DLL is a .NET managed code DLL (not a COM shell) and does not require Visual FoxPro. Supported functions execute very quickly, since they are all written in .NET and compiled into managed .NET DLL code. Included is a help and training offline CHM help file, as well as Visual Studio.NET built-in dynamic help using the same CHM help file. Full IntelliSense and online help are included for VFP functions when programming in any .NET language. Using the VFP Toolkit or .NET, most Visual FoxPro features become available in Visual Basic.NET or any other .NET language. Functions such as STRTOFILE () convert a line to a file in only one line of code.

Further, he says this:

The Visual FoxPro Toolkit for .NET does not teach Visual Studio.NET developers how to program, but it allows developers to do .NET programming a lot faster and write less code based on what they are familiar with when these features reduce coding in general and whole. It is not pseudo-VFP syntax, it is the "real" VFP syntax and works most naturally in Visual Basic.NET because it does not require a namespace. You still need to learn the Windows.NET Framework and Visual Basic.NET (or any .NET language). What this toolkit does helps Visual FoxPro developers using .NET, because there is a much faster learning curve for .NET programming that allows you to use these features. Visual FoxPro Toolkit for .NET does not replace any .NET language. It complements and improves the experience and performance of .NET programming.

+1
source

You can easily do this using the following code:

 string lcString = @"C:\Example"; if(!lcString.Substring(lcString.Length -1, 1).Equals(@"\", StringComparison.InvariantCulture)) { lcString += @"\"; } 
0
source

In this case, I always used path.TrimEnd('\\') + "\\" . And since I used this code quite often, I wrote an extension method:

 public static string AddTrailingSlash(this string s, char slash = '\\') { return s.TrimEnd(slash) + slash; } 
0
source

All Articles