473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Split a String

Hi,

I am retrieving a list of book titles from a web service. What I'd like to
do is shorten the titles, if possible. For example, there is a book titled
"Malicious Mobile Code: Virus Protection for Windows". It would be nice if
I could trim the title down to the colon (it would just say Malicious Mobile
Code).

Is there an easy way to accomplish this task?

Thanks,
Roshawn
Nov 21 '05 #1
4 1575
Maybe you could use the instr() function to return the first occurence of the
colon, and then use the left or mid function to return the left side of the
name?

mid:
http://msdn.microsoft.com/library/de...l/vafctMid.asp
left:
http://msdn.microsoft.com/library/de.../vafctleft.asp

instr:
http://msdn.microsoft.com/library/de...vafctinstr.asp

Does this help you?

"Roshawn" wrote:
Hi,

I am retrieving a list of book titles from a web service. What I'd like to
do is shorten the titles, if possible. For example, there is a book titled
"Malicious Mobile Code: Virus Protection for Windows". It would be nice if
I could trim the title down to the colon (it would just say Malicious Mobile
Code).

Is there an easy way to accomplish this task?

Thanks,
Roshawn

Nov 21 '05 #2
Roshawn,
In addition to the VB runtime functions r_burgess suggested.

You can use String.Split to split the name.

Dim title As string = "Malicious Mobile Code: Virus Protection for
Windows"
Dim parts() As String = title.Split(":"c)

The parts(0) will contain "Malicious Mobile Code", while parts(1) will
contain " Virus Protection for Windows"

Alternatively you could use String.IndexOf & String.SubString along with
String.Trim to remove leading & trailing white space.

Dim title As string = "Malicious Mobile Code: Virus Protection for
Windows"
Dim index As Integer = title.IndexOf(":"c)
Dim parts(1) As String
parts(0) = title.Substring(0, index).Trim()
parts(1) = title.Substring(index + 1).Trim()

Note you can use String.LastIndexOf if you want to split the name on the
last ":" instead of the first ":" if there are multiple ":" in the name.

I normally avoid mixing the VB runtime functions (InStr, Left, Right, Mid)
with the String methods (String.IndexOf, String.SubString) within the same
function/class/project/solution as the runtime functions are 1 based
indexes, while the String methods are 0 based indexes.

Hope this helps
Jay

"Roshawn" <ud****@bellsouth.net> wrote in message
news:ed**************@TK2MSFTNGP15.phx.gbl...
Hi,

I am retrieving a list of book titles from a web service. What I'd like
to
do is shorten the titles, if possible. For example, there is a book
titled
"Malicious Mobile Code: Virus Protection for Windows". It would be nice
if
I could trim the title down to the colon (it would just say Malicious
Mobile
Code).

Is there an easy way to accomplish this task?

Thanks,
Roshawn

Nov 21 '05 #3
Thanks guys (and gals just to be polite) for your prompt responses. These
techniques are just what I was looking for.

Roshawn
Nov 21 '05 #4
Very nice. I didnt even think of those calls. Learn something new everyday.

"Jay B. Harlow [MVP - Outlook]" wrote:
Roshawn,
In addition to the VB runtime functions r_burgess suggested.

You can use String.Split to split the name.

Dim title As string = "Malicious Mobile Code: Virus Protection for
Windows"
Dim parts() As String = title.Split(":"c)

The parts(0) will contain "Malicious Mobile Code", while parts(1) will
contain " Virus Protection for Windows"

Alternatively you could use String.IndexOf & String.SubString along with
String.Trim to remove leading & trailing white space.

Dim title As string = "Malicious Mobile Code: Virus Protection for
Windows"
Dim index As Integer = title.IndexOf(":"c)
Dim parts(1) As String
parts(0) = title.Substring(0, index).Trim()
parts(1) = title.Substring(index + 1).Trim()

Note you can use String.LastIndexOf if you want to split the name on the
last ":" instead of the first ":" if there are multiple ":" in the name.

I normally avoid mixing the VB runtime functions (InStr, Left, Right, Mid)
with the String methods (String.IndexOf, String.SubString) within the same
function/class/project/solution as the runtime functions are 1 based
indexes, while the String methods are 0 based indexes.

Hope this helps
Jay

"Roshawn" <ud****@bellsouth.net> wrote in message
news:ed**************@TK2MSFTNGP15.phx.gbl...
Hi,

I am retrieving a list of book titles from a web service. What I'd like
to
do is shorten the titles, if possible. For example, there is a book
titled
"Malicious Mobile Code: Virus Protection for Windows". It would be nice
if
I could trim the title down to the colon (it would just say Malicious
Mobile
Code).

Is there an easy way to accomplish this task?

Thanks,
Roshawn


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
4
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
4
by: Crirus | last post by:
There is a function somewhere to split a string with multiple tokens at a time? Say I have this: aaaa#bbbbb*ccccc$dddd I whould like to split it so the result whould be aaaa bbb
14
by: Ron | last post by:
Hello, I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? .... data += ASCII.GetString(buffer, 0,...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.