I have several prefixes that I need to append to workbook names. They range from: CR12, LT23, EF232, RF232..
I need a way to take the left 2 characters of the string, and say if
(left(prefix, 2) == "LT")
{
formatAdditions();
}
How can I do this in C#?
Loading
VulpesPosted Feb 11, 2013, 5:48 AM
Here's a link to the docs for the VB.NET runtime library:
http://msdn.microsoft.com/en-gb/library/c157t28f(VS.100).aspx
richard smithPosted Feb 11, 2013, 8:01 AM
Jignesh TrivediPosted Feb 10, 2013, 11:04 PM
hi,
you may use either your own function or extension method.
with own function
namespace testProject
{
class Program
{
public static string Left(string myString, int index)
{
if (!string.IsNullOrEmpty(myString) && myString.Length > index)
{
return myString.Substring(0, index);
}
return string.Empty;
}
static void Main(string[] args)
{
var leftstr = Left("EF232", 2);
}
}
}
or use extension method
namespace testProject
{
public static class MyClass
{
public static string Left(this string myString, int index)
{
if (!string.IsNullOrEmpty(myString) && myString.Length > index)
{
return myString.Substring(0, index);
}
return string.Empty;
}
}
class Program
{
static void Main(string[] args)
{
var otherLeftStr = "EF232".Left(2);
}
}
}
hope this will help you.