Substring in C#

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2007
Posts: 5
Reputation: wien is an unknown quantity at this point 
Solved Threads: 0
wien wien is offline Offline
Newbie Poster

Substring in C#

 
0
  #1
Jan 1st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Substring in C#

 
0
  #2
Jan 1st, 2009
There are quite a few string operations - have a look under "String"
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,042
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 305
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Substring in C#

 
0
  #3
Jan 1st, 2009
The String class even has a Substring method!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 14
Reputation: Fabm is an unknown quantity at this point 
Solved Threads: 1
Fabm Fabm is offline Offline
Newbie Poster

Re: Substring in C#

 
0
  #4
Jan 1st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Substring in C#

 
0
  #5
Jan 2nd, 2009
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?!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Substring in C#

 
0
  #6
Jan 2nd, 2009
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
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,042
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 305
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Substring in C#

 
0
  #7
Jan 2nd, 2009
Originally Posted by Fabm
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.
Last edited by ddanbe; Jan 2nd, 2009 at 7:54 am.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Substring in C#

 
0
  #8
Jan 2nd, 2009
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


  1. Left(somevariable, 3)

transfers to

  1. 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...)
Last edited by rapture; Jan 2nd, 2009 at 4:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Substring in C#

 
1
  #9
Jan 2nd, 2009
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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,042
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 305
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Substring in C#

 
0
  #10
Jan 3rd, 2009
Originally Posted by rapture
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!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 4078 | Replies: 18
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC