String Builder
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
Can't you store the IDs in a
List<string>
as they come in. YOu then have a list of IDs and can use this to build your string for storage at teh end."More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
A StringBuilder most of the time is used to improve the performance when a series of operations needs to be performed on textual data, that would otherwise be stored in a string (each operation would create a new string object and copy its data). Ultimately, when the assembly of the string is done, one normally converts the StringBuilder to a string using the ToString() method. Since your string operation is very simple (just a concatenation) there is no point in using StringBuilder. And as you figured, you need a string object in order to use the nice String methods such as Split(). [Correction: if you do this several times, there may be a performance gain in useing StringBuilder, but in the end you have to convert back to a string]. BTW: if FIELD_SEP is a constant, there is not much point in adding it permanenty; instead, I suggest you append it to the one string you are dealing with, when and where you need it. :) -- modified at 12:00 Friday 3rd August, 2007
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
Hi, The Sting class has a function "Split()", which returns array of String after spliting the String on the basis of a char.
Manoj Never Gives up
-
A StringBuilder most of the time is used to improve the performance when a series of operations needs to be performed on textual data, that would otherwise be stored in a string (each operation would create a new string object and copy its data). Ultimately, when the assembly of the string is done, one normally converts the StringBuilder to a string using the ToString() method. Since your string operation is very simple (just a concatenation) there is no point in using StringBuilder. And as you figured, you need a string object in order to use the nice String methods such as Split(). [Correction: if you do this several times, there may be a performance gain in useing StringBuilder, but in the end you have to convert back to a string]. BTW: if FIELD_SEP is a constant, there is not much point in adding it permanenty; instead, I suggest you append it to the one string you are dealing with, when and where you need it. :) -- modified at 12:00 Friday 3rd August, 2007
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Luc Pattyn wrote:
Since your string operation is very simple (just a concatenation) there is no point in using StringBuilder.
Actually, as it was done for every item that was recieved, using a StringBuilder is a good method. As he wants to process the separate items afterwards, putting them together as a single string is of course a bad idea, regardless of the method used. :)
--- single minded; short sighted; long gone;
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
why r u making it complicated.Instead use stack or queue class and store each items one by one in it.They r fast-efficient and easy to program.:rose:
Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)
-
Hi all. I have an application which will recieve ids from some other application. Now i need to store the incoming ids to a string builder, so that i can use it for later use.For this i have created a string builder as follows stringbuilder strIncomingEventID=new stringBuilder() and inside the receiving method i used the below stmts strIncomingEventID.Append(incomingmessage + Convert.ToChar(FIELD_SEP) ) now i want to retrieve each ids from it..for my manipulation... i am not getting split properties or any thing which is useful..can any one help me in this .One more thing is that i am appending a constant FIELD_SEP to end of incoming message when i store , so that when i want to retrieve the ids ,it will be useful..is it right method.Please advise me how to get the value from the string builder Thanks in advance
Regards DilipRam
-
string [] ids = strIncomingEventID.ToString().Split(...);
that should do the trick... :-DV. If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
Yes, that would work, but it's a terrible work around. Concatenating the values into a big string, only to split it again... Why not encrypt the string, put it in an xml document, save the xml document to disk, load it from disk, extract the data, and decrypt it, while you're at it? ;) Chances are that the id:s aren't even strings at all, so a List<int> would be the best place to store them.
--- single minded; short sighted; long gone;
-
Yes, that would work, but it's a terrible work around. Concatenating the values into a big string, only to split it again... Why not encrypt the string, put it in an xml document, save the xml document to disk, load it from disk, extract the data, and decrypt it, while you're at it? ;) Chances are that the id:s aren't even strings at all, so a List<int> would be the best place to store them.
--- single minded; short sighted; long gone;
Guffa wrote:
Concatenating the values into a big string, only to split it again... Why not encrypt the string, put it in an xml document, save the xml document to disk, load it from disk, extract the data, and decrypt it, while you're at it?
Good thinking man, this is even better. :-) I merely replied to his actual problem ;p
V.
Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive -
Yes, that would work, but it's a terrible work around. Concatenating the values into a big string, only to split it again... Why not encrypt the string, put it in an xml document, save the xml document to disk, load it from disk, extract the data, and decrypt it, while you're at it? ;) Chances are that the id:s aren't even strings at all, so a List<int> would be the best place to store them.
--- single minded; short sighted; long gone;
You forgot to insert the xml document in that SQL database and retrieve it :laugh:
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
-
string [] ids = strIncomingEventID.ToString().Split(...);
that should do the trick... :-DV. If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
-
A StringBuilder most of the time is used to improve the performance when a series of operations needs to be performed on textual data, that would otherwise be stored in a string (each operation would create a new string object and copy its data). Ultimately, when the assembly of the string is done, one normally converts the StringBuilder to a string using the ToString() method. Since your string operation is very simple (just a concatenation) there is no point in using StringBuilder. And as you figured, you need a string object in order to use the nice String methods such as Split(). [Correction: if you do this several times, there may be a performance gain in useing StringBuilder, but in the end you have to convert back to a string]. BTW: if FIELD_SEP is a constant, there is not much point in adding it permanenty; instead, I suggest you append it to the one string you are dealing with, when and where you need it. :) -- modified at 12:00 Friday 3rd August, 2007
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Hi Thanks for the reply.The think here is that i will be having multiple strings coming from other application.It will be not single one or it can come any time and i need them for futher processing.So i am using string builder ,,but then how can i split these ids from the string builder.I hope i am clear abt my requirment
Regards DilipRam
-
why r u making it complicated.Instead use stack or queue class and store each items one by one in it.They r fast-efficient and easy to program.:rose:
Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)
-
Hi thanks for the reply,but the thing is that i will not be having single string value...there will be multiples values coming and i have to store it and so i how can use a string to store it.pls explain
Regards DilipRam
If my answer did not satisfy your needs, please explain more clearly what you actually want.
V.
Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive -
Hi thanks for the reply,but the thing is that i will not be having single string value...there will be multiples values coming and i have to store it and so i how can use a string to store it.pls explain
Regards DilipRam
What's wrong with my first answer. As they values come in, add them to a container. A List would do. Then when they are all in, you can traverse the list doing what you want with them.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
Hi thanks for the reply But no idea on how to work with stacks and queues...
Regards DilipRam
Well, containers are the solution to your problem so learn how to use them. Containers are the solution to a lot of problems.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
Hi Thanks for the reply.The think here is that i will be having multiple strings coming from other application.It will be not single one or it can come any time and i need them for futher processing.So i am using string builder ,,but then how can i split these ids from the string builder.I hope i am clear abt my requirment
Regards DilipRam
ramdil wrote:
how can i split these ids from the string builder
As I said, use ToString() to turn StringBuilder into string, then String.Split() to split it. But for your situation, I would not use StringBuilder at all. Seams like you need some kind of stream or a named pipe, and perform WriteLine and ReadLine on it. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
If my answer did not satisfy your needs, please explain more clearly what you actually want.
V.
Stop smoking so you can: Enjoy longer the money you save. Moviereview ArchiveHi thanks for the reply Actually i have an application which will recieve messages from some other application.It can happen at any time.Now i have a recieve method for this purpose..but i dont want to do any operations as soon as i recieve any id but i want it to be used later .So inorder to not loose the incoming id, i decided to used string builder so that i can append one by one the id's which are coming..but now if i want to extract it or split it,,i dont have any split method in string builder ,its only in string ..so what do i need to do. Hope i am clear.
Regards DilipRam
-
Hi thanks for the reply,but the thing is that i will not be having single string value...there will be multiples values coming and i have to store it and so i how can use a string to store it.pls explain
Regards DilipRam
If you are saying that the values come in as something like: "a,b,c" "d,e,f" etc. Then split each incoming list of IDs as it arrives and use a collection to store the individual values.
-
Hi thanks for the reply,but the thing is that i will not be having single string value...there will be multiples values coming and i have to store it and so i how can use a string to store it.pls explain
Regards DilipRam
ramdil wrote:
the thing is that i will not be having single string value...there will be multiples values coming and i have to store it and so i how can use a string to store it.
You don't store it in a single string. It's pointless to put the strings together, as you want them separate later on. Just use a
List<string>
. Add each string to the list, then when you have recieved them all, you can easily access all the strings. If the values are id:s, as the name suggests, you can use aList<int>
instead. Why store them as strings, if they aren't?--- single minded; short sighted; long gone;