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

VulpesRank #55 · 29.2K reputationPosted Feb 11, 2013, 12:48 AM EST
Here's a link to the docs for the VB.NET runtime library:
http://msdn.microsoft.com/en-gb/library/c157t28f(VS.100).aspx
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 10, 2013, 6:04 PM EST
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.
richard smithRank #8,268 · 225 reputationPosted Feb 11, 2013, 3:01 AM EST