String Split function

Hi all,

My brains rusted, as the end of the day is approaching..
here is a simple one for experts.

I have a string which contains string like this" 2008-2009"
I want it to split and use them further, like 2008 and 2009

i'm using Vb.net in code behind

can you please check whats wrong and lead me to a correct solution

             Dim StringYear = RecievedFinancialYear
             Dim StringMonth= recievedMonth
            
Dim partsArray As String() = StringYear.Split("-")

            For i As Integer = 0 To 1

                Dim Year1 As String = partsArray(0)
                Dim Year2 As String = partsArray(1)

            Next
            
I want to populate a label control based on this year. 

If StringMonth='November' or 'October' then
lblYear.text=year1
else
lblYear.text=year2
end if

Thanks for the help
0
SaraDob
5/4/2009 9:37:48 PM
asp.net.getting-started 91979 articles. 2 followers. Follow

2 Replies
669 Views

Similar Articles

[PageSpeed] 30

Something like this?

Dim StringYear As String = RecievedFinancialYear
Dim StringMonth As String = recievedMonth
Dim partsArray As String() = StringYear.Split("-")

If partsArray.Length.Equals(2) Then
    Dim Year1 As String = partsArray(0)
    Dim Year2 As String = partsArray(1)

    If StringMonth.Equals("November") Or StringMonth.Equals("October") Then
        lblYear.text = Year1
    Else
        lblYear.text = Year2
    End If
End If
  
- William

Please mark the most helpful reply/replies as "Answer".

Give some of my PWSK modules a try.
0
whighfield
5/4/2009 10:55:28 PM
Dim partsArray As String() = "2008-2009".Split("-") 

Dim Year1 As String = partsArray(0)

Dim Year2 As String = partsArray(1)

Dim StringMonth As String = "November"

If StringMonth = "November" Or StringMonth = "October" Then

lblYear.text = Year1

Else

lblYear.text = Year2

End If

 

0
mo
5/5/2009 1:32:44 AM
Reply:

Similar Artilces:

Why String.Split(char[]) is possible but String.Split(string[]) is Not!
Hi everyone, i have a string for e:g String st= "Delete a record****** *************************************************** Delete Manually PatID=123456 PatName=navdeep *****Delete a record****** *************************************************** Delete Manually *****************PatID=123 PatName=navdeep6666" I need to Split this String by "Delete a record" string. Now, str[] will contain the array elements. str = st.Split("Delete a record"); Please Help Regards Navdeep check below link or try code  http://www.codeproject.co...

Getting error in Net::SFTP with get function
------=_Part_7028_3315294.1193837808284 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I have the following code as part of my program; print "---=========> $file, $localFile\n"; $sftp -> get( $file, $localFile ) || warn("errrrr0rrrrr _---> $!".$sftp->status."\n");^M Even though it has downloaded the file properly, it is giving the following message: ---=========> /trading/tiscrdenhlist10310000.txt.old, /export/home/crdadm/rajeev/tiscrdenhlist103...

splitting the string without using split function
...\M3\1_Requirements\Ashish_M3_Functional_Requirements_Document.doc splittiing the string in such a way that  i wil get the last part of the stringstarted with \ (splitting the string without using split function) so output will be  Ashish_M3_Functional_Requirements_Document.doc The System.IO.Path class provides a safe way for extracting all the different parts of a file name/path, so in this case I would be tempted to use that.RegardsDave...

Getting Start With .net
hi i'm intersted to learn asp.net (vb or delphi) . i programming with delphi6 but i'd like to tp know something about programming in internet specially with .net . i hear about microsoft.net with delphi 7 that i can programming with delphi in .net .... is it right ? what 's our opinian about it ? and better to learn Vb.Net or continu with delphi(or delphi.net) thanks. Ali Darabian I think there is some support for Delphi in .Net. However, you will find much more support from the user community if you choose a more popular language such as VB.Net or C#. Since your al...

how to get start with .NET
the net help people installed  to my desktop 1-microsoft visual studio .NET enterprise developer 2003 2-microsoft .NET framework 1.1 what else do i need ...???  and how can i try with some simple code in VS.Net and run it to see wat happen...????? please help If you want to develope web applications, then you'll also need IIS on your PC.  That'll require XP-Professional or Windows 2000/2003, but XP-Home edition won't allow IIS installation. As for how to get started, you can search the web for some tutorials or buy a good book on VS.  The topic is way too vast to...

split string by string
Hi All I am trying to split a string with other string. Does any one help me how to do this.I have "237943--;--dgsa78a--;--dasd732" I want to split with --;-- And ideas please thanks,Aruna.G     string contents = "237943--;--dgsa78a--;--dasd732"; you can do contents.split(';')which would split it on ; Thanks,Karan~ Remember To Mark The Post(s) That Helped You As The ANSWER ~ You can use String.Split(String[], StringSplitOptions)   string source = "237943--;--dgsa78a--;--dasd732"; string[] ...

Where to start and how did you get started?
Hi, I have had a feeling for a long time to jump into the adds market for some time due to my low income (shooting for the stars) and I don't have anything better to do these days. But I find it really difficult not to give up due to lack of guides (what I can find atleast) and all the hard words which only makes me confused. But I won't give up. Never. Not sure if this is the right place to post this, but I deffinitly would be really greatfull for help getting started. How did you get started? +If there are any teacher that wanna show me the ropes private, I can give payment with ...

Getting all text at start of a string
Hello,I have a string (from a weather feed) that looks like:Monday: Mainly Sunny, 25.5°C Is it possible to get everything before the :So I can just get the day, and not the conditionsThe idea is that the feed looks likeMonday: asdsfasfMonday Night: asdsfasfTuesday: AFASFetc,Thanks  Try this: string s = "Monday: Mainly Sunny, 25.5°C"; string d = s.Split(':')[0];Thanks, EdMicrosoft MVP - ASP/ASP.NET...

how to get rid of the function string
Hi, when I use rs_helpexception id,v to get a logged transaction, there are function string inserted into it, if I need manually apply this transaction, I could not do that in a isql session. could anyone tell me how to get rid of the funtion string from there? Thanks. Bin "Bin Yu" <b-yu2@uchicago.edu> schrieb im Newsbeitrag news:3B0E96C1.597939AF@uchicago.edu... > Hi, > when I use rs_helpexception id,v to get a logged transaction, there are > function string inserted into it, if I need manually apply this > transaction, I could not do that in a ...

split string in vb.net
HiI'm using vb.net 2.0. Here is my input string "When the string needs to be splited to fit on the lines, it is tried to split the string at a gab between words." I want to split string for the given word "to fit on the lines" and i gave like this code: Dim string1 As String() = strBody.Split("to fit on the lines") But the output came like this : string1 {Length=16} String()  (0) "When " String  (1) "he s" String  (2) "ring needs " String  (3)&nb...

problem with function splitting strings
simply I hopeI have 2 functions which take '1,2,45,66' as an argument, split the numbers, joins to a table of values and returns OK, but I want to use the field from Table1 as an argument If I call the function from a procedure including Table1 I get Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Function1", or the name is ambiguous. Table1 - I have a table has a field of delimetered numbers 1,2,45,66Function1 - splits the String and returns a table of integers OKFunction2 - Joins the results from Function1 and retur...

Getting started with JScript.NET
I'm a Javascript and Actionscript developer, and the thought of being able to do server-sides in something I know was too good to resist. Does anyone know some good tutorials for developing ASP.NET pages in JScript?  I can find lots of console code, but simple things are hard: like I can't even figure out how to print something out to the web page (just a string). What I'm really trying to do is access a database, verify a login, and print JSON out to the response.  What should I do to start?  Is there a better way to do this? (IE: using some JSON library already?). I'm commun...

stack trace while creatting function strings and function string with keywords..
Hii..I are using a user defined function string. and I am facing problems on creating functions ..like select and select with lock functions for the tables which has column names same as keywords. table:create table newclient(SOURCE varchar(20),SOURCE_ID int).. SOURCE is the primarykey.. For select function.. the function string looks like .... create function string repdef_newclient.rs_select for my_fun_class scan 'select * from newclient where SOURCE = ?SOURCE!user?' output language 'select * from newclient where SOURCE= ?SOURCE!user?' go while creati...

Getting started .net website
Hi folks,Does anyone here know of a good website to just sit back and read for learning .net? Thanks in advance.Baldeep Right here... Click the Get Started and Learn sections here. Quite a few out there - - this one, has a lot of good videos -  also ASPNet101.com, but then, I might be a little prejudiced David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(P...