C♯ method TimStart() method

Hi guys,
I working on pretty old project from 2010 (.net framework 4)
 I need to validate entries of string value:
1. Take it off leading and trailing empty space from input string.
2. Leading 'zeros' from input string and after length should be not greater then 10.

strValue = "  0001234567890 "

strValue = strValue.Trim()
str = stringValue.TrimStart('0')
if(str.length> 10) {
...popup message
}
.....

Open in new window


Problem this:
method Trim()            => works
method TrimStart()    => error: Object doesn't support property or method 'TrimStart'

Any ideas?
Thank You
DariusAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DariusAuthor Commented:
Acepted result should be:

strValue: '1234567890'
Neil RussellTechnical Development LeadCommented:
strValue = "  0001234567890 "

strValue = strValue.Trim()
str = strValue.TrimStart('0')
if(str.length> 10) {
...popup message
}
.....
AndyAinscowFreelance programmer / ConsultantCommented:
TrimStart is a member of the string class


strValue = "  0001234567890 "

strValue = strValue.Trim()
str = stringValue.TrimStart('0')    //What is stringValue - or do you mean strValue
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

DariusAuthor Commented:
Some grammer mistakes: strValue
Neil RussellTechnical Development LeadCommented:
Yes that is the solution I gave above, correcting the typo by Darius
DariusAuthor Commented:
Thank Neil for corection...
it_saigeDeveloperCommented:
What Neilsr said...  Proof of concept:
using System;

namespace EE_Q28973366
{
	class Program
	{
		static void Main(string[] args)
		{
			string value = "  0001234567890";
			// Removes all leading and trailing white-space characters from the string.
			value = value.Trim();
			// Removes all leading occurances of the specified character, 0.
			string result = value.TrimStart('0');

			Console.WriteLine("Resulting string - {0}; {1}.", result, result.Length > 10 ? "has more than 10 characters" : string.Format("has exactly {0} characters", result.Length));
			Console.ReadLine();
		}
	}
}

Open in new window

Produces the following output -Capture.JPG
We could also simplify your code somewhat by chaining method calls:
using System;

namespace EE_Q28973366
{
	class Program
	{
		static void Main(string[] args)
		{
			string value = "  0001234567890";
			// Removes all leading and trailing white-space characters from the string and then
			// removes all leading occurances of the specified character, 0.
			string result = value.Trim().TrimStart('0');

			Console.WriteLine("Resulting string - {0}; {1}.", result, result.Length > 10 ? "has more than 10 characters" : string.Format("has exactly {0} characters", result.Length));
			Console.ReadLine();
		}
	}
}

Open in new window

Which gives us the same output.

-saige-
DariusAuthor Commented:
The problem is for trimStart() method
AndyAinscowFreelance programmer / ConsultantCommented:
Strange error message though unless stringValue is actually declared
Neil RussellTechnical Development LeadCommented:
TrimStart method works fine in C# .NET4
Your error was in the use of a wrong variable name.  Have you pasted my corrected code and run it?
Neil RussellTechnical Development LeadCommented:
And don't forget that "The problem is for trimStart() method" is NOT the same as
"The problem is for TrimStart() method"

Make sure that all capitalization is correct both in your code and in code submitted in the question please or we could be here a while.
DariusAuthor Commented:
On my way home, check then...
AndyAinscowFreelance programmer / ConsultantCommented:
As I mentioned earlier that error message would not be produced from a simple typo between strValue and stringValue, it would need stringValue to be declared and also not to be a string type of variable.

This sounds like you have given a piece of air code (not copied/pasted actual code).  If that is correct please do NOT do that in future.  I have seen in multiple questions with edited/invented code being used where the original error has been accidentally corrected and/or another error introduced.
DariusAuthor Commented:
Tried to separate Trim() and TrimStart('0') methods to see results.   TrimStart() gives error...
results below

error on debuging
DariusAuthor Commented:
else if (invoiceId.Trim().lenght > 15) {
            warn = "!" + "Invoice ID has more then 15 characters.\n";
            //in this case the page is not reloaded, so the button has to be enabled and the cursor back to 'default'
            document.body.style.cursor = 'default';
            document.getElementById("btnSend").onclick = '';
        }
        else if (invoiceId.TrimStart('0').lenght > 10) {
            warn = "!" + "Invoice ID has more then 10 characters.\n";
            //in this case the page is not reloaded, so the button has to be enabled and the cursor back to 'default'
            document.body.style.cursor = 'default';
            document.getElementById("btnSend").onclick = '';
        }

Open in new window

it_saigeDeveloperCommented:
I was afraid of this based upon the samples you provided.  This is javascript, not C# (updated tags to reflect).

Not to split hairs but length is mispelled.  Also as convention the javascript method is trimStart not TrimStart.  

-saige-
DariusAuthor Commented:
change to 'trimStart' same issue...

else if (invoiceId.trimStart('0') == "00120") {
            ....
}
it_saigeDeveloperCommented:
I've been looking but I do not believe that javascript supports trimStart in the way you have characterized without using something like jQuery or another library that extends the language specification.  The best that I can find is the Microsoft specification that says trimStart is used to trim whitespace from the beginning of a string:  https://msdn.microsoft.com/en-us/library/bb310800.aspx

Looking in the Mozilla Javascript Reference, I cannot find trimStart specified: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

I'll admit though, I am not an expert on javascript.

-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.