473,809 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1605
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.SubStrin g 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.LastInde xOf 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.SubStrin g) 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****@bellsou th.net> wrote in message
news:ed******** ******@TK2MSFTN GP15.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.SubStrin g 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.LastInde xOf 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.SubStrin g) 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****@bellsou th.net> wrote in message
news:ed******** ******@TK2MSFTN GP15.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
31184
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 will split myString up using the delimiter of 1 space so that
11
2512
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 strings. I wonder if someone else had ever stumbled on it before, and if it has a good reason to work like it is. Both implementations take two parameters: the separator character and the max number of splits (maxsplit). However, string.split() accept
6
6385
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
10927
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 empty strings in the resulting string array.
4
5794
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
6895
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
34982
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, bytesRead) .... Dim parts() As String = data.Split(vbCrLf)
3
9671
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... field1...field2...field3...
5
5882
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() = Microsoft.VisualBasic.Strings.Split(aLine, vbNewLine, -1, CompareMethod.Binary)
2
2199
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 = "field != value" result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.