Click here to Skip to main content
15,896,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to seperate the digits how to get the digits before '\' and after slash seperately
i did like this
C#
private String removeCodeNumber(String covCode)
       {
           String[] cov=covCode.Split('/');
           if (cov.Length > 2)
           {
               return cov[0].ToString();
           }
           else
           {
               return covCode;
           }
       }
       private String removeCovcode(String codenbr)
       {
           String[] cov = codenbr.Split('/');
           if (cov.Length > 2)
           {
               return cov[1].ToString();
           }
           else
           {
               return codenbr;
           }
       }




example covcode is having 161\47899
now i need sepereate these two values
Posted
Updated 10-Oct-13 1:03am
v2
Comments
Tanuj Rastogi 10-Oct-13 6:16am    
Could you please elaborate on what output you are expecting and how it is troubling you ?
OriginalGriff 10-Oct-13 6:22am    
The code you show should (probably) do what you describe - so I don't see what problem you are having. Perhaps if you give us an example of what you are passing these two methods, what you expect to get out, and what you do get?
Matt T Heffron 11-Oct-13 13:42pm    
Have you gotten a solution to this yet?

Hey there,

Try \\ in the Split method:
C#
covCode.Split('\\')


Let me know if it helps.

Azee...
 
Share this answer
 
Your code should work.

Is your problem the direction of your slash? Your written explanation is using back-slash but your code is using forward-slash?
 
Share this answer
 
Comments
OriginalGriff 10-Oct-13 7:27am    
Not a solution - this is a comment only.
Please do not post comments as solutions.
Stephen Hewison 10-Oct-13 8:01am    
How have you decided this is not a solution? If the direction of the slash is the problem and me asking the question give him his answer, is this not a solution? Surely that's for the person who asked the question to decide?
In both methods you are checking if the result of the Split() has greater than 2 items.
(I'm also assuming that you wanted the backslash as you implied in the text of your question.)
Try:
C#
private String removeCodeNumber(String covCode)
{
  // in this case no checking of the result length is necessary!
  // if the search character isn't found then an array containing only the covCode is returned.
  return covCode.Split('\\')[0];
}

private String removeCovcode(String codenbr)
{
  String[] cov = codenbr.Split('\\');
  if (cov.Length >= 2)
  {
    return cov[1];    //.ToString(); is unnecessary, it's already a string
  }
  return codenbr;     // else is unnecessary because above return prevents "fall-thru"
}
 
Share this answer
 
There is a split function in c# with the name of "Split()" and in this you can give the character behalf of which you want to split ...
note that index after spliting start from zero .. try it
 
Share this answer
 
Comments
OriginalGriff 10-Oct-13 7:27am    
Reason for my vote of one: read the question - he is using the Split method, and correctly (probably) using the index values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900