Split a String - not sure how to ask the question

  • Thread starter Thread starter J Stoodley
  • Start date Start date
J

J Stoodley

I am in a learning curve right now, and want to become well aquanted
with VB.NET. So, I have two questions. 1 is technial the other is
resource related.

1. I need to strip a single character from a string. I will explain
why. I am creating a page that will add users to Active Directory. I
collect the FirstName value (based on a pre-composed Excel
spreadsheet) and want to strip just the first initial so I can create
the sAMAccountName based on the users first initial.

I assume I will use the string.split function somehow, but I cannot
seem to populate my array with each of the characters of the FirstName
string.

So far I have come up with

stringarray = strfirstname.split(????? - this is where I am confused)


2. What is a recommended reference book for VB.NET. There are many,
but I want one that other's recommend. I am fairly new to VB.NET
programming.




THANKS!!!
 
Hi "J Stoodley"
stringarray = strfirstname.split(????? - this is where I am confused)
first position of a string
x=strfirstname.substring(0,1)' place and lenght

where I in this example asume that the first inital is on the first
position.

You can use in VB.net a lot of string commanodo. To call some
The microsoft.visualbasic functions, the system.string member, the reg
expressions..................
Normaly you use or the microsoft visual.basic functions or the system.string
members.
The first are like VB6 and earlier, the later more like all C, J and
javascripts.
VB functions are (Mid, right, left etc)
String members (tolower, substring, indexof)
2. What is a recommended reference book for VB.NET. There are many,
but I want one that other's recommend. I am fairly new to VB.NET
programming.
I did not read a book about VB.net .
The new walkthougs from Microsoft become better and better.
But I think you will get other advises too.

I hope this helps
Cor
 
Im not sue if this is what you want ?

Dim strings() As Char

Dim str As String = txtIn.Text



strings = str.ToCharArray

txtOut.Text = strings(0).ToString
 
Hi Stoodley--

Answer to Question 1...

....this code works and MAY do what you need (if I have understood your
question correctly)...



Private Sub btnTestParsing01_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnTestParsing01.Click

Dim strValue As String
Dim intIndex As Integer
Dim objList As ArrayList

'Fill string value.
strValue = "AName"
objList = New ArrayList()

'Fill array with characters.
For intIndex = 0 To strValue.Length - 1
objList.Add(strValue.Chars(intIndex))
Next

'Print characters from array.
For intIndex = 0 To objList.Count - 1
Response.Write("objList.Item(intIndex).ToString() = " _
& objList.Item(intIndex).ToString())
Response.Write("<br />")
Next

End Sub



Answer to Question (2)...

There are a lot of factors here, such as learning style, preferences, time
spent reading, experience, and so on. That said, here is a general rule.

First, assuming one is totally new to language X and to programming, then
one should read a beginner's book, from start to finish. I recommend
something like "Sam's Teach Yourself X in 21 Days" or "Wrox's Beginning X".
After you have this first book, you will KNOW how to pick out you next one.




HTH.

--Mark





I am in a learning curve right now, and want to become well aquanted
with VB.NET. So, I have two questions. 1 is technial the other is
resource related.

1. I need to strip a single character from a string. I will explain
why. I am creating a page that will add users to Active Directory. I
collect the FirstName value (based on a pre-composed Excel
spreadsheet) and want to strip just the first initial so I can create
the sAMAccountName based on the users first initial.

I assume I will use the string.split function somehow, but I cannot
seem to populate my array with each of the characters of the FirstName
string.

So far I have come up with

stringarray = strfirstname.split(????? - this is where I am confused)


2. What is a recommended reference book for VB.NET. There are many,
but I want one that other's recommend. I am fairly new to VB.NET
programming.




THANKS!!!
 
you can do it a bunch of ways, but one easy one would be Dim s as String =
Microsoft.VisualBasic.Left(FirstName, 1) 'Will return the first character in
the string

Split will split it based on a delimitter, but if you don't need the other
values, use either Left as above or Substring

2) Visual Basic .NET Core Reference by Fransesco Balena is excellent, and
Coding Techniques for Visual Basic .NET by John Connell is another great on.
On DataAccess, David Sceppa's ADO.NET Core Reference is a must have, and
anything that Bill Vaughn writes should probably be in your library.

Cheers,

Bill
 
WOW, I cannot beleive the number of replies I recevied already.
THANKS!!!

I figured out my solution, I think the most efficient way, using a
substring.
 
Hi Jeff,

.NET makes <everybody> feel like a novice for a while. You've just gotta
climb that hill. :-)

Regards,
Fergus
 
Back
Top