Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

need basic help splitting string...

 

hello,

I need help parsing a string in c#... I can't find an example online, just one of those days I guess.

 

What i'm trying to do is to parse the following string at the '&'. I want to get the values so I can then put them into a database table.

RESULT=126&PNREF=V63F0A7A001D&RESPMSG=Under review by Fraud Service&AUTHCODE=010101&AVSADDR=Y&AVSZIP=Y&IAVS=N&PREFPSMSG=Review CeilingAmount&POSTFPSMSG=Review

 

Can anyone get me started or point me in the right direction? :o

I've looked into the split method... seems like it may work but i'm not sure if it will do what i'm looking for.

 

Thanks

Edited by reagan123
  • *Experts*
Posted

I think the split method is your best and easiest bet.

I hope that you can easily convert this into C#.

Dim values() As String = RESULT.Split("&")
Dim i As Interger
For i = 0 to values.GetUpperBound(0)
   MessageBox.Show(values(i))
Next

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

hmm.. seems to work

but now i have another problem

that gives me an array with the values like this correct?

RESULT=126

&PNREF=V63F0A7A001D

&RESPMSG=Under review by Fraud Service

&AUTHCODE=010101

&AVSADDR=Y

&AVSZIP=Y

&IAVS=N

&PREFPSMSG=Review CeilingAmount

&POSTFPSMSG=Review

 

What i need to do know is get the value on the right hand of the '=' sign and assign that to a variable.

 

Is that possible? I may be approaching this in the wrong way.

  • Leaders
Posted
You can use String.IndexOf to get the character index of the equals sign and String.Substring to get a portion of the string. If you are using VS or #Develop, type in "String." and a list of all sorts of nifty functions and properties comes up.
[sIGPIC]e[/sIGPIC]
Posted
Back in the days of VB6 i did it with Instr and mid. I think you can do the same thing still. I think marble_eater revealed a big secret when he advised you to study all the string functions, trust me learning helps.
  • *Experts*
Posted

I've been beaten to the post by the guys above. Your array will include the variable, an equal sign and a value. As marble eater mentioned, there are alot of different ways to separate the value from the array string:

Using IndexOf - Replace, Remove, SubString

Using Regular Expressions

Using the split method again with a "=" delimiter

And more that we haven't mentioned.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

i'm lost again...

 

here's what i've come up with so far.. any comments or suggestions appreciated.

 

string test = "RESULT=126&PNREF=V64F0A7D0BC2&RESPMSG=Under review by Fraud Service&AUTHCODE=010101&AVSADDR=Y&AVSZIP=Y&IAVS=N&PREFPSMSG=Review CeilingAmount&POSTFPSMSG=Review";
		
string[] arInfo = new string[12];
// define which character is seperating fields
char[] splitter  = {'&'};

arInfo = test.Split(splitter);
for(int x = 0; x < arInfo.Length; x++)
{
    Response.Write(arInfo[x]);	
}
	
}

 

not sure where to go from here.... :(

 

i'm in the process of looking at the string properties... I'm still not sure how to assign the values to a variable....

Posted

this seems to get all of the values on the right hand side of the equals sign. I still can't figure out how to assign these values to variables? Sorry for being such a basic question. Thanks so much for the help so far!!!

 

string test = "RESULT=126&PNREF=V64F0A7D0BC2&RESPMSG=Under review by Fraud Service&AUTHCODE=010101&AVSADDR=Y&AVSZIP=Y&IAVS=N&PREFPSMSG=Review CeilingAmount&POSTFPSMSG=Review";
		
string[] arInfo = new string[12];
// define which character is seperating fields
char[] splitter  = {'&'};
           
arInfo = test.Split(splitter);
for(int x = 0; x < arInfo.Length; x++)
{
   	int y = arInfo[x].IndexOf("=");
string z = arInfo[x].Substring(y+1);
Response.Write(z);
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...