Manipulating a string
-
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. R -
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. RHi I have added comments for each line. Hope it helps you.
string StrObjectItems = "";
StrObjectItems = "Object1,Item1,Item2-Object2,Item1,Item2-Object3,Item1,Item2";//You need two string arrays - one for each pipeline and another is that each comma within pipeline strings
string[] StrObjectsArray = StrObjectItems.Split(new char[] { '-' });
//loop thro' each objects as you have splitted into array of strings.
for (int i = 0; i <= StrObjectsArray.GetUpperBound(0); i++)
{
//this string will have first object that is 'Object1,Item1,Item2'
string StrObjects = StrObjectsArray[i].ToString();//again split the above string as an array
string[] StrItemsArray = StrObjects.Split(new char[] { ',' });//loop thro' each objects' items as you have splitted into array of strings.
for (int j = 0; j <= StrItemsArray.GetUpperBound(0); j++)
{
string StrItems = StrItemsArray[j].ToString();
}
}-- modified at 5:23 Tuesday 6th March, 2007
Rate this message. Thank you. Harini :)
-
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. RI don't see any pipe (|) characters in the string. I suppose that you mean that the parent strings are delimited by a dash (-). To get the parent string in an array, split on a dash:
string[] parents = sample.Split('-');
The propertyparents.Length
will give you the number of strings. To get the child strings of a parent, split it on a comma:string[] children = parents[0].Split(',');
--- single minded; short sighted; long gone;
-
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. RThanks to both of you that replied. It all makes sense now. Thank you once again! R
-
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. RHi. the following line looks for the character '-' in the string. the flag checks whether it is true or not. then it checks where the character is found, and the substrings are taken into other strings. bool flag=false; flag=sample.Contains("-"); if(flag==true) { int m=sample.IndexOf("-"); string s1 = sample.Substring(0, m); // s1 will contain Object1,Item1,Item2 sample = sample.Remove(0, m+1); // now the sample will contain //Object2,Item1,Item2-Object3,Item1,Item2 } Hence you can repeat the procedure to store the other substrings, maybe in a string arraylist. i hope this helps. keshav kamat siemens india
-
Hi guys, I needs some help with this challenge I'm facing please. This is my challenge: I have a string with "parent object" and item in the format of pipe delimited between "parent objects" and comma delimited between items. Like this
string sample = "Object1**,**Item1**,**Item2**-**Object2**,**Item1**,**Item2**-**Object3**,**Item1**,**Item2";
How will I go about manipulating the string to use the "objects" and items in this format. I basically need to get the "object" and the items and in some cases I will need to work with one entire entry at a time, lets sayObject1,Item1,Item2
. I am not to familiar with theSystem.String
functions yet and would love if anybody around here could show me how this could be done or possibly some references. Thanks. RAlternatively, one can use the Split funtion depending upon a special character. string[] string1=sample.Split("-"); the number of members are identified by the string1.Length property, which will give you the count of the members in the new string after the split. Keshav Kamat India.