473,396 Members | 2,018 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,396 software developers and data experts.

how to get string within string

12
Hi,

I really need you guys' help with getting string within string. I have an address validation code that will send a request string to UPS, and if the address is validated, UPS will send a response string back. The problem starts here. Once I get the response string, I want to be able to display only city, state and zipcodes, but I don't know how to grab those values from the response string. The response string looks like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <AddressValidationResponse>
  3. <Response>
  4. <TransactionReference>
  5. <CustomerContext>Customer Data</CustomerContext>
  6. <XpciVersion>1.0001</XpciVersion></TransactionReference>
  7. <ResponseStatusCode>1</ResponseStatusCode>
  8. <ResponseStatusDescription>Success</ResponseStatusDescription></Response>
  9. <AddressValidationResult>
  10. <Rank>1</Rank>
  11. <Quality>0.9254</Quality>
  12. <Address>
  13. <City>MADISON</City>
  14. <StateProvinceCode>WI</StateProvinceCode></Address>
  15. <PostalCodeLowEnd>53701</PostalCodeLowEnd>
  16. <PostalCodeHighEnd>53708</PostalCodeHighEnd></AddressValidationResult></AddressValidationResponse> 
So, the only values I want to display are (for example)Madison, WI, 53702, 53708.

Thanks
aboon
Feb 16 '09 #1
8 2152
vekipeki
229 Expert 100+
Check the XmlReader class: http://msdn.microsoft.com/en-us/libr...29(VS.80).aspx
Feb 17 '09 #2
aboon
12
@vekipeki
Hi, Thanks for the link..I still couldn't get it to work because the XmlReader get text from a file, but the response string I got from UPS does not store in a file. I'm not sure how to just read a string within that string. I tried using SubString, but that didn't work either because the the length of the response string is not consistent. It depends on the values that user type in, and the result of the validation.

please help,
thanks
Feb 17 '09 #3
tlhintoq
3,525 Expert 2GB
I've never used XML before (shock) and yet I can see there are 12 overrides for the .Create method - several of them use a System.IO.Stream as the source. So you are not limited to just reading XML files from hard disc.

I would think you can take your incoming data, turn it into a stream if it isn't already, and then feed it to the .Reader object.

TIP:
If you aren't accustomed to it, use the tools that Visual Studio gives you, such as the Intellisense.

As you start typing 'XMLReader.' as soon as you hit the period a list of available methods and properties comes up. Type 'Create(', then as soon as you type the left parenthises ( a list of all the overides comes up showing you all the various ways you can call this method with different combinations of arguments. You can hit the up/down arrow keys or click on the up/down arrows of the hothelp that just popped up to see the different overrides.
Feb 17 '09 #4
aboon
12
I'm not sure how to do it exactly..
This is part of the code.after I got user input(city, state, zip), send the request string to UPS to validate the address.
UPSOnlineInterface.Components.Address addr = new UPSOnlineInterface.Components.Address();
addr.City = this.txtCity.Text.Trim();
addr.StateProvinceCode = this.ddlState.SelectedValue;
addr.PostalCode = this.txtZip.Text.Trim();
string response = reques.AddressValidateRequest(accReq, addr);
string encodedString = HttpUtility.HtmlEncode(response).Replace("&lt;", "<BR>&lt;").Replace("<BR>&lt;/", "&lt;/");
The "encodingString" is the result of the response string which looks like the top post..the next step is to get the values, and dispay them which I still couldn't figure out.

thanks
Feb 17 '09 #5
vekipeki
229 Expert 100+
there are 12 overrides for the .Create method
As tlhintoq said, using Intellisense can help you find the override that works for you - using the up/down keys you will browse through different tooltips for that method.

Note the Intellisense tooltip in the figure below:



In this case, your method accepts a TextReader, so it means you can create a StringReader from your string and pass it to your method (because StringReader is a concrete implementation of abstract TextReader class).
Feb 18 '09 #6
aboon
12
In this case, your method accepts a TextReader, so it means you can create a StringReader from your string and pass it to your method (because StringReader is a concrete implementation of abstract TextReader class).
Hello,
Thanks you very much for the example. I tried using StringReader and get the innerXml as a result.
Expand|Select|Wrap|Line Numbers
  1.  XmlDocument xmlDoc = new XmlDocument();
  2.         xmlDoc.Load(new StringReader(response));
  3.         XmlNode elem = xmlDoc.DocumentElement;
The innerXml looks something like this:
Customer Data1.00011Success10.9169
MADISONWI
535625356220.9169
MADISONWI
535935359330.9169
MADISONWI
537015370840.9169
MADISONWI
537115371150.9169
MADISONWI

Now, I would like to add the innerXml result into a dropdownlist. Is there a way to do this???

Thank you very much for all your help.
aboon
Feb 20 '09 #7
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. ComboBox bob = new ComboBox();// Or use an existing control
  2. string MyNewItem = MyXMLcalculationMethod();// Your method that parses the XML and returns a string to be added to the ComboBox
  3. bob.Items.Add(MyNewItem);
  4.  
Feb 21 '09 #8
aboon
12
thank you very much for all your help
Feb 24 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Igor2004 | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
0
by: Igor Nikiforov | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
4
by: Ralph Noble | last post by:
Does anyone know of a string function in Access that will allow me to count the number of instances one string occurs within another? Or if there is some sort of word count function? If there is,...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
4
by: Mark | last post by:
OK. Here we go. I have an ASP.NET application that does many hits to a SQL Server DB on a separate server. When I first created this application (2 years ago) and was very new to ASP/ASP.NET, to...
1
by: pmelanso | last post by:
Hello, I am trying to create a method that will see if one string contains a different string: This is what I have so far: Private Function containString(ByVal string1 As String, ByVal...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
0
by: ReeceSeeSharp | last post by:
Having difficulty trying to get this code in .NET (C#) to print out this string EXACTLY as it prints out within Java using a) the MD5 hashing algorithm and B). In Java here's how a string "ididnot"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
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,...
0
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...
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...

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.