c# string manipulation

have a stored proc which accepts a  PARAMETER  @str varchar(8000)  in sql server 2000
Lets say I have the following string which is concatenated by  "+" sign and its more than 8000
Now I want to send First 500 IDs at a stretch as parameter to the stored proc and rest of the IDs again

like  Send first  500 IDs the current logic can take the same string as it is no need of splitting it.
instead of whole string which is > 8000  lets split the string into 2 parts and send to the stored proc can it be shown.. example of string is
some Logic like  if  strstudentIds.length > 7500 kind of logic has to be applied

"99582+99926+9062+90683+90205+90308+90339+89655+89679+90007+89454+89520+89564+89109+89121+87776+87111+87160+87401+86831+86961+87016+86049+86365+86713+84389+85470+85503+83807+8412+83765+83767+83806+89071+88145+84290+88151+88438+88051+88113+83055+83229+82902+82493+82603+82844+82272+82459+82127+82208+87410+81512+81612+81120+80634+80664+80683+8029+8043+80533+80063+80093+79380+79422+79423+78724+79030+79191+78624+78636+78720+78468+78474+78581+781415+781508+782049+780459+78088+779132+779445+780118+77780+778045+778108+776814+777650+77778+77637+776466+77659+775623+775816+81170+81476+80690+774494+775183+7753+773640+774443+771825+772183+772858+771666"
dotnet0824Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
Where does this data go?  To a single database field?

1.  It sounds like you could redesign your table structure so that you avoid the multi-value field!!!
2.  If you expect data longer than 8000 characters, you should probably be using a text field--and a text parameter.
3.  See 1 above...




0
dotnet0824Author Commented:
thats ok............current stored proc everything working.. all i need is  splitting the string into 2 parts and sending those 2 string values to stroed proc
0
dotnet0824Author Commented:
lets forget about the stored prc..generally speaking how can we store the first 500 id's in one string in a vraible loop and next it should proceed to other IDs
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

JimBrandleyCommented:
The code below does what you want. Change idsToSendFirst to 500 for your use.

Jim

string ids = "12345+6789+01234+567890+123+456+789";
int idsToSendFirst = 3; // Change this to 500
string firstHalf = string.Empty;
string remainder = string.Empty;
int idCount = 0;
int pos = 0;
while ((idCount < idsToSendFirst) && (pos > -1))
{
   pos = ids.IndexOf('+', pos + 1);
   if (pos > -1)
      idCount++;
}
if (pos > -1)
{
   firstHalf = ids.Substring(0, pos);
   remainder = ids.Substring(pos + 1);
}
else
   firstHalf = ids;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulHewsCommented:

using System.Text.RegularExpressions;
...
 
        private string[] SplitIDs(string ToSplit, int Number) 
        { 
            List<string> sl = new List<string>(); 
            Match last=null; 
            foreach (Match m in Regex.Matches(ToSplit, "([\\d]*\\+){" + Number.ToString() + "}")) { 
                sl.Add(m.Value);
                last = m;
            } 
            sl.Add(ToSplit.Substring(last.Index + last.Length)); 
            return sl.ToArray(); 
        } 

Open in new window

0
dotnet0824Author Commented:
excellent.. thanks a lot
0
PaulHewsCommented:
You're welcome.  But seriously, even though it may be working, multivalue fields are a big no-no.  It's a violation of first normal form:

http://en.wikipedia.org/wiki/First_normal_form
http://www.regdeveloper.co.uk/2006/07/18/multivalued_datatypes_access/
0
JimBrandleyCommented:
My pleasure.

PaulHews - from a previous post, I think he's breaking them up in the SP, not dumping them all into a single column.

Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.