473,666 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing string

Hello all,

I am creating a string based on data returned from an oracle db into a
hashtable.

string tmpFirstName = tmphashtable["FIRST_NAME "].ToString();

The Database has a column called FIRST_NAME but the return also has the
middle initial so my string look something like this "FirstName M" I
don't need the M. Can nay one show me an example on how to parse the
space and the M from the string to just get the FirstName?
Thanks,

KC

Nov 16 '05 #1
6 3323
I suppose the other catch is someone who has two words as a first name, or
more than one initial.

something like?

// convert "Freg H" to "Fred"
if ( firstName[ firstName.Lengt h - 2 ] == " " )
firstName = firstName.SubSt ring ( 0, firstName.Lengt h - 2 );

// convert "Freg JH" to "Fred"
else if firstName[ firstName.Lengt h - 3 ] == " " )
firstName = firstName.SubSt ring ( 0, firstName.Lengt h - 3 );


"Netmonster " <ne***********@ yahoo.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello all,

I am creating a string based on data returned from an oracle db into a
hashtable.

string tmpFirstName = tmphashtable["FIRST_NAME "].ToString();

The Database has a column called FIRST_NAME but the return also has the
middle initial so my string look something like this "FirstName M" I
don't need the M. Can nay one show me an example on how to parse the
space and the M from the string to just get the FirstName?
Thanks,

KC

Nov 16 '05 #2
KC,

First, if the column is a string, you can most likely just cast it to a
string. Calling ToString is superfluous:

string tmpFirstName = (string) tmphashtable["FIRST_NAME "];

Then, you can call the Split method on the string, and get an array of
the parts delimited by whatever you choose. In this case, it would be a
space.

// The parts.
string[] parts = tmpFirstName.Sp lit(new char[]{' '});

The first name would be in the array at index 0 then.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Netmonster " <ne***********@ yahoo.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello all,

I am creating a string based on data returned from an oracle db into a
hashtable.

string tmpFirstName = tmphashtable["FIRST_NAME "].ToString();

The Database has a column called FIRST_NAME but the return also has the
middle initial so my string look something like this "FirstName M" I
don't need the M. Can nay one show me an example on how to parse the
space and the M from the string to just get the FirstName?
Thanks,

KC

Nov 16 '05 #3
Thanks Nicholas.. Splitting the string worked great..

KC

Nov 16 '05 #4

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:eu******** ********@tk2msf tngp13.phx.gbl. ..
I suppose the other catch is someone who has two words as a first name, or
more than one initial.


I think a name like J Edgar [Hoover] would fail. I think the first thing you
should do is to scan the text for space characters. Only then should you try
to split the string. Don't. make the assumptions about the location of this
character.

/Fredrik
Nov 16 '05 #5
KC

Alternavily from splitting.

if (str.IndexOf(" ") != -1) str = str.Substring(0 , str.IndexOf(" "));
I hope this helps,

Cor
Nov 16 '05 #6
Out of curiosity, why is it better to use a string cast rather than
ToString()? Is it a performance issue?

/Mats-Lennart

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eC******** ******@TK2MSFTN GP11.phx.gbl...
KC,

First, if the column is a string, you can most likely just cast it to a string. Calling ToString is superfluous:

string tmpFirstName = (string) tmphashtable["FIRST_NAME "];

Then, you can call the Split method on the string, and get an array of
the parts delimited by whatever you choose. In this case, it would be a
space.

// The parts.
string[] parts = tmpFirstName.Sp lit(new char[]{' '});

The first name would be in the array at index 0 then.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Netmonster " <ne***********@ yahoo.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello all,

I am creating a string based on data returned from an oracle db into a
hashtable.

string tmpFirstName = tmphashtable["FIRST_NAME "].ToString();

The Database has a column called FIRST_NAME but the return also has the
middle initial so my string look something like this "FirstName M" I
don't need the M. Can nay one show me an example on how to parse the
space and the M from the string to just get the FirstName?
Thanks,

KC


Nov 16 '05 #7

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

Similar topics

8
9436
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
2
3946
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\ You selected the file named AAA.XML getXmlAlgorithmDocument(): IOException Not logged in
6
7652
by: BerkshireGuy | last post by:
Does anyone know of a good function that will parse out parts of an SQL statement that is passed to it in seperate variables? It should be able to parse statements that contain ORDERBY, WHERE, GROUP, etc. Thank you, Brian
9
1979
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a good time in this process to create a new instance of my Message object. While messing around with...
3
3311
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception: “Unexpected end of file while parsing Name has occurred” isbeing thrown. Following is the part o xml I am trying to read: <CHECK_ITEM_OUT>
3
2698
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def RN(name, regex): """protect using () and give an optional name to a regex""" if name:
2
4864
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important data reading. For instance this is my buffer string: 012301234FFFFFFxFFFFFFxFFFFFFx Where the FFFFFF is my Hex data I need to read. I am using the "x" as a separater as I was having problems using the VbCrLf. But I think
6
1921
by: gw7rib | last post by:
I have a program that needs to do a small amount of relatively simple parsing. The routines I've written work fine, but the code using them is a bit long-winded. I therefore had the idea of creating a class to do parsing. It could be used as follows: int a, n, x, y; Parser par; par << string;
1
2960
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. I've tried doing pre processing with find/replace to get rid of these characters but then I get another type of error "An unexpected end of file parsing CDATA has occurred" So to get around that error I've added in unicoding and removing...
1
4382
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or Stack code and parsing code my professor i does not like me using buffer reader on my code and my professor did even give me an example code for parsing as well as pop push top or Stack code and i don't know how to do this code into parsing and pop push...
0
8866
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...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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
8639
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...
1
6192
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
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.