Through playing I have noticed that whenever I type the name of a string, for example str, with a . after it a list appears with common and all functions availible.
Commom:
Contains
EndsWith
IndexOf ..... etc.
I am trying to find which functin would accomodate me the best. I am currently using the .Contains to find if a specific "key" word appears in the string I just read in. But what I don't know how to do is extract data that appears after the "key" words.
Can someone please help me.....!!!!
Example:
Itinerary for Doe,John on 01-01-1001
The informaion in yellow is the data that I need. The red ar the "key" words.

String Functions
Jamie Clayton
will REGEX help you
Ant999
Hello All.
QWERTYtech:
Don't feel bad, REGEX's give me a migraine!
If you're wanting something to illustrate the string methods, this little snippet should do it. It's a bit bloated, but I figured clarity was better than brevity in this case.
HTH.
Wayne Munro
Frank,
Alright.... I used your code snippet to test how everything worked but whenever I ran it and displayed the information stored in DataValues() it wasn't right. It showed that DataValues(0) was NULL and DataValues(1) was Doe,John . What did i do wrong
UPDATE: Aight, I'm an idiot... I solved it... The data was stored in the DataValues(1) position and DataValues(2) position... My bad.
caltex
John.Doe
Okay, so say I had a line of info and I just needed one particular thing out of it.
How would I get that particular thing out b/c it has dynamic info before it.
NBaig
Mark,
Thanks for the example, it is actually helping me to start understanding what I need to do but I have one question that requires an example.. Based off of what you wrote before:
The thing is that I have more than just that particular line that I need to get info off of.
Example of the format of my .txt document
Itinerary for the Period of 01-01-1001 to 01-08-1001
Itinerary for Doe,John on 01-01-1001
<Usless data on this line>
<Usless data on this line>
<Usless data on this line>
ID : 123456 Name: Doe, Jayne
<Usless data on this line>
<Usless data on this line>
<Usless data on this line>
Notes:
Itinerary for ...... do this over and over.
The red are the "key" identifiers.
The yellow are the info that I need.
Also, how would u suggest to store the info im collecting, if I was going to have to recall all of this information and make multiple calendars fore eacth Employee
KoryS
In your case, for the string you gave, its easy enough to split the string (use .Split()) on white space, and work through each token that you get back, saving the ones that you are interested in.
AllanRoy
Im not sure... I've never heard of REGEX.
Gareth Hunter
Hello All.
QWERTYtech:
Well, yes, that code snippet was merely meant to illustrate the concept that strings may be considered to be sets of substrings, and subject to manipulation, either through indexing or, like Frank Carr pointed out, through the Split() method. You simply need to identify the salient data that you need to gather, and modify the code to parse each variation of the input string. Learn by doing.
As far as how to store that data, that would depend on how you intend to implement the calendar. It could be something as simple as string arrays, or as complex as an EmployeeCalendarData object that you create. There are a lot of ways of doing it, and there is no such thing as "the one perfect way", so don't worry about that. Just get in there and do it.
HTH.
AaronTM
Here's a way to do what you want:
Dim TestLine As String = "Itinerary for Doe,John on 01-01-1001"
Dim SplitValues() As String = {"Itinerary for ", " on "}
Dim DataValues() As String = TestLine.Split(SplitValues, StringSplitOptions.RemoveEmptyEntries)
Debug.Print(DataValues(0))
Debug.Print(DataValues(1))
The SplitValues is an array of strings that you want to split up the rest of the line with. The result is a string array with the values you want. This method does work off the assumption that your 'key' words will remain fairly constant, although you could load the SplitValues() array dynamically as well.
Regular Expressions (REGEX) does offer you more options but its syntax is a bit daunting when you first see it.
batterhead
cdun2
bessermt
I've done things like that in the past and the easiest way I found was to have a start key and an end key.
(this code was done very fast, there are much amelioration to do)
Module
Module1 Sub Main() Dim str As Stringstr = "Itinerary for the Period of 01-01-1001 to 01-08-1001"
str &= "Itinerary for Doe,John on 01-01-1001"
str &= "<Usless data on this line>"
str &= "<Usless data on this line>"
str &= "<Usless data on this line>"
str &= "ID : 123456 Name: Doe, Jayne"
str &= "<Usless data on this line>"
str &= "<Usless data on this line>"
str &= "<Usless data on this line>"
str &= "Notes: "
Console.WriteLine(GetString(str, 0, "for the Period of ", " to"))
Console.WriteLine(GetString(str, 0, "to ", "Itinerary for"))
Console.WriteLine(GetString(str, 4, "Itinerary for ", " on"))
Console.WriteLine(GetString(str, 4, "on ", "<Usless d"))
Console.WriteLine(GetString(str, 4, "Name: ", "<Usless "))
Console.ReadLine()
End Sub Public Function GetString(ByVal data As String, ByVal start_pos As Integer, ByVal start_key As String, ByVal end_key As String) As String Dim pos1, pos2 As Integerpos1 = data.IndexOf(start_key, start_pos) + start_key.Length
pos2 = data.IndexOf(end_key, pos1)
Return data.Substring(pos1, pos2 - pos1).Trim() End FunctionEnd
ModuleTCSC
Hello All.
QWERTYtech:
I'm sorry, but I haven't used CrystalReports much, so whatever I told you would probably be wrong. It's my understanding that CrystalReports is intended and designed to be used as a report layer for a SQL Server Database, and its object model pretty much mirrors the database schema, but you should take that with a pretty sizeable grain of salt.
MSDN Library has a ton of info and tutorials for CrystalReports. That's the first place I would look if I were you.
HTH.