Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Don-1-2011

The problem is that i have to capture incrementing value between don- and -2011 through substring function, this value will increase record by record that can be 1,10,111,1000, 10001, please help me in this regard.

thanks in advance
Posted
Comments
Sunasara Imdadhusen 11-Apr-11 7:05am    
Please confirm following:
you need something like
Don-1-2011
Don-2-2011
Don-3-2011
Don-4-2011
:
:
Don-n-2011
Asifhmca 11-Apr-11 7:26am    
Yes i need like this i just want to capture 1 or 2 or 3 or 4

The easiest way is to use String.Split to chop the string into three parts:
Dim input As String = "Don-1234-2011"
Dim parts As String() = input.Split("-"C)
Dim justTheMiddle As String = parts(1)
 
Share this answer
 
Comments
Manfred Rudolf Bihy 11-Apr-11 7:13am    
Somebody has been reading my mind again! ;)
5+
OriginalGriff 11-Apr-11 7:17am    
Well, if you ever forget your PIN number, you know who to ask! :laugh:
Sunasara Imdadhusen 11-Apr-11 7:15am    
Good call!
C#
Dim parts() as String
Dim don = "don-10001-2011"
Dim result as String
parts = don.Split("-")
result = parts(1) 'incase of zero based array else 2 for 1 based array indices


Hope that helps!

-MRB
 
Share this answer
 
Comments
Sunasara Imdadhusen 11-Apr-11 7:15am    
Good!!
path=path.Substring(3, path.Length - 7);(
3 corresponds to don and -7 if(3+4) 4 corresponds to 2011)
 
Share this answer
 
v2
Comments
Asifhmca 11-Apr-11 7:46am    
Thanks for ur valuable help but value comes with - like -3- or -100- or -1000- . i need only like 3 m 100 or 1000
avigodse 11-Apr-11 9:31am    
You could have used OriginalGriff's answer, its right and safe in many ways.
I haven't tested this but it will give you the idea of what you need to do to get it working.

VB
dim LastIndex as integer  = 0
LastIndex = Record.LastIndexOf("-")

'As you know Don- will never change so you can hard code that part in the substring or look into the indexof function
messagebox.show (Record.SubString(4, LastIndex))



This is also a good reference to string functions String Functions with examples[^]
 
Share this answer
 
Comments
Sunasara Imdadhusen 11-Apr-11 7:16am    
Good!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900