473,385 Members | 1,707 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,385 software developers and data experts.

Parse string and grab only certain data

16
Im trying to parse a recv from a telnet session then only grab certain data.

Heres an example of the recv that Im storing into a string:

Internet 204.189.124.205 0 001a.a01f.4e5a ARPA Vlan122

The only part I want is the mac address which is in bold.

Im trying to parse it while running it into a for loop so when it gets to the 4th section it will store that in another string. But its not working, anybody have any ideas?

Expand|Select|Wrap|Line Numbers
  1. public static string ParseMac(string macOut)
  2.         {
  3.  
  4.  
  5.             for (int i = 0; i < 10; i++)
  6.             {
  7.                 if (i == 4)
  8.                 {
  9.                     char[] delimiterChars = { ' ' };
  10.  
  11.                     string[] outPut = macOut.Split(delimiterChars);
  12.  
  13.                     foreach (string s in outPut) { }
  14.  
  15.                 }
  16.               }
  17.             return (s);
  18.  
  19.             }
Feb 5 '08 #1
4 1345
Plater
7,872 Expert 4TB
You have the right idea, but your loops are in the wrong order.

If you only care about the fourth part, consider something like this
Expand|Select|Wrap|Line Numbers
  1. public static string ParseMac(string macOut)
  2. {
  3.    char[] delimiterChars = { ' ' };
  4.    string[] outPut = macOut.Split(delimiterChars);
  5.    //index is 0,1,2,3,etc so the "fourth" part is [3]
  6.    string PartWanted = outPut[3];
  7. }
  8.  
Feb 5 '08 #2
Prodian
16
Thanks for the help, thats working fine when theres one space between each word but on the telnet output it could be 1 space or 5 spaces. Anyway around this?
Feb 5 '08 #3
Plater
7,872 Expert 4TB
The split() has an overload to wipe out blank entries (which would happen if two or more spaces are together), use that and it should be ok.
Feb 5 '08 #4
Prodian
16
I did this instead:
Expand|Select|Wrap|Line Numbers
  1. string macOut = "Internet      204.189.124.205   16  0000.0c07.ac01   ARPA Vlan101";
  2.  
  3.             Regex r = new Regex(" +");
  4.             string [] splitString = r.Split(macOut);
  5.  
  6.             string PartWanted = splitString[3];
Thanks for the help.
Feb 5 '08 #5

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

Similar topics

8
by: laredotornado | last post by:
Hi, I'm using PHP 4 and trying to parse through HTML to look for HREF attributes of anchor tags and SRC attributes of IMG tags. Does anyone know of any libraries/freeware to help parse through...
9
by: Alex Nordhus | last post by:
Im trying to grab a colum of data from a text file and write it to a new file. I am having trouble getting It to write the data to newlines. Python is making it one Long string without any spaces...
5
by: tony collier | last post by:
I have ..... enum day {monday, tuesday, wednesday}; myArray=5; i=(int)Enum.Parse(typeof(day), wednesday);
2
by: kaede | last post by:
Hi all, Given the following textfile (i.e test.txt) 5 5 5 2 E aeiou 4 3 Y abcdefghij
0
by: neil | last post by:
For integration with a credit card processing gateway i need to be able to capture a small XML formatted string passed back to my page from the processing company. It is sent back to the same...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
11
by: cindyfaith | last post by:
I have one question regarding a code I wrote to parse a data file My code looks like this open($FILE, "C:\\data\\NCI sample.txt") or die "oh oh can't open"; open(OUT,...
0
by: industrial | last post by:
After several attempts, I am in need of some expert help parsing lines of text w/ VB6 Pro. Here's the scenario: It starts with an Excel sheet which is an export from a Peachtree accounting app. I...
1
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.