Hi all

I am trying to write a C# dataform where a company ID is created from the first four letters of the customers name + a number. Any ideas? As Left() is not used. and I can't find a reference to substrings.

Wien

Recommended Answers

All 18 Replies

There are quite a few string operations - have a look under "String"

The String class even has a Substring method!

Why doesn't someone answer with just a quick example instead of saying things like "lookup string"?

As a VB-oriented programmer, if someone mentions Left() and they are trying to find an alternative in C#, then a C# expert should just post the c# equivalent of:
Left(somevariable, 3) & somenumber

Fab

Lizr and Danny don't answer people with code especially who don't show their effort in solving easy problem, they're right, aren't they?!

We dont just hand you the answer because you have demonstrated you dont know how to find out information for yourself, something as simple as this should be something you find in the helpfile - if your question had been more of

Ive got this code, I dont see why its producing <this> when I expected <that> sure, you're likely to see a more informative response, but when the answer is a case of Press F1 for help and read the info you already have to hand, you shouldnt need someone to tell you

As a VB-oriented programmer, if someone mentions Left() and they are trying to find an alternative in C#, then a C# expert should just post the c# equivalent of:

I would not call myself an expert. I like programming and I know something about C#, and I like to help people.
Left, Right and Mid are all flavours of one thing in C# : Substring

If I was new to C# and I would ask myself "How can I do Left in C#?"and LizR gave me the answer "He man look under String"(see #2) The first thing I would do then is lookup the String class and see what it does. If I found a method that would solve my needs I would post a thank you an mark the thread as solved. If I still had the faintest idea of how to go on I would post a new question and mention the things I already had done.

I'm just a guy trying to learn so take my advice with a grain of salt -
first off, I agree with the others, and they are not heartless, just tired of a lot of people working on a project for school somewhere who want us to write their code for them.

If I'm not mistaken what you want is something like this

Left(somevariable, 3)

transfers to

somevariable.Substring(0,3);

at least I think that's correct.

(By the way, look at the number of threads they have marked as "solved" - they are willing to help, they just want some effort from the poster first...)

Rapture is right, its not that we hate you or want you to hate us either. However the addage, give a man a fish, he eats for the day, give a man a fishing rod he can eat for a year.

If we give you an a line of code, what did you learn, we will feed you.

If we give you places to look and how to find your answers..
You learn to find them yourself and work faster and smarter.

commented: I like eating fish +3

somevariable.Substring(0,3);

Must be somevariable.Substring(0,2);

P.S.
You would not like to know how many times I made such mistakes!

Must be somevariable.Substring(0,2);

P.S.
You would not like to know how many times I made such mistakes!

That's what I'm talking about!
Fab

Then why didn't he mark it as solved?

Idonno

only problem with this teach a man to fish deal you have running is that not everyone has Visual Studio, some people are compiling using free software with no help files, and online help from Microsoft is practically Japanese to a weekend programmer.

But I do understand, although i understand things best with an example, simply searching for an answer to this problem in google yields the exact answer in the first result by just searching "mid() in C#" http://www.csharphelp.com/archives4/archive616.html but manytimes i have been searching for some help on something and had to waste my time reading forum posts that were top search results that don't answer me at all.

so I am undecided, sometimes I just don't know where to go, and I have no code to post.

further note, that link is a good one, it shows how for someone accustomed to VB style left, mid, and right functions to reproduce them in C# so they can even still be called using left, mid, and right respectfully.

Live and Dream in code my friends.

only problem with this teach a man to fish deal you have running is that not everyone has Visual Studio, some people are compiling using free software with no help files, and online help from Microsoft is practically Japanese to a weekend programmer.

Visual C# Express is free.

Visual C# Express is free

Indeed. I can't argue with that, but still many programmers don't use Visual Studio.

At the same time, MSDN gives examples to pretty much everything, so even if you dont understand it fully, it does explain it, if you dont understand something on MSDN, perhaps you would learn to teach yourself better by asking something like..

Im trying to do <this> I found <this> on MSDN but I dont understand <this> small section I dont see how it changes <x> to <y> or why that works but when I do <this> it doesnt.

First: I am not recieving any benefits from MicroSoft.
Second: Visual Studio IS good, be it C++, VB or C# or even another language you use in it.
-It has a marvelous editor(with Intellisence).
-It has an incredible debugger.
-Your files are organised in a project.
-It has designer features to implement buttons, menus, listboxes etc.
-It has great help capabilities.
etc. etc.
The only thing I had in the beginning was that I felt out of control. It felt like everything was done for me. Which is not true in fact, you must still know what you are doing when using all those fancy aids.

Much like ddanbe, people who know me, know as a whole I actually would probably be placed in the "anti microsoft" camp, so, Im not getting any benefits, payback either..

VS (express or otherwise) is a good product, its fast and snappy. The express ones doubley so, and of course free.

Sure, if you're working on linux or mac's you can have good reason express isnt for you, but anyone with windows, Id have to question why if you are new to c# you chose to make your life so much harder than you needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.