Solved

vb string parsing help needed

Posted on 2011-09-23
5
235 Views
Last Modified: 2012-05-12
I have a file of names that I need to parse out into a shorter version of the name as I write them to a new file.  In each record, the string psOrig contains the company name, and it might be one, two, or three words or more, with spaces in between each word.  For example, psOrig might contain 'Sony', or 'Sony Electronics', or 'Sony Electronics Corporation', etc.  I need a way to put only the first two words into psNew, meaning that if psOrig contains 'Sony Electonics', or 'Sony Electronics Corporation', all that would end up in psNew would be 'Sony Electronics'.  And, if psOrig only contains one word, then that's what I would want in psNew.

I need help with coding this, with a routine that can detect the spaces and parse this out properly for each name.....TIA
 
0
Comment
Question by:sasllc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 total points
ID: 36590650
Dim psOrig as String = "Sony Electronics Corp"
Dim parts as String() = psOrig.Split(New Char() {" "c})
Dim psNew as String = parts(0) + " " + parts(1)
0
 
LVL 3

Author Comment

by:sasllc
ID: 36590839
This works great--except for the situation where psOrig was a single word name, such as 'Sony'.  In that case I get this error: 'Index was outside the bounds of the array.'  Any good solution to this problem?
0
 
LVL 40
ID: 36590948
Dim psOrig as String = "Sony Electronics Corp"
Dim parts as String() = psOrig.Split(New Char() {" "c})
Dim psNew As String

If parts.Count = 2 Then
   psNew = parts(0) + " " + parts(1)
Else
   psNew = parts(0)
end if
 
0
 
LVL 3

Author Comment

by:sasllc
ID: 36590978
When I use this syntax, I get this error: 'count is not a member of System.Array'.  As I typed in the command, I only had seven options, and 'count' was not one of them.  I wonder if maybe this is because I'm working in the limited 'smart device' environment, as I develop this program for a scanner.  The options I show are:

clone
get length
get lower bound
get upper bound
length
rank
SetValue

Any workaround in this environment?
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 250 total points
ID: 36591011
Sorry, I mixed arrays and collections (they are very similar), and I use collections a lot more often.

Use Length instead of Count.

0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question