4

I need to return maximum 9 digits of the following abc string .How to do this?

public string test()
{
  string abc="asdhfjsdfkjhfiovjalksdhafbvklxkjszjhd";
  return abc;
}
User
  • 1,644
  • 10
  • 40
  • 64

4 Answers4

5

Use String.Substring:

public string test()
{
  string abc="asdhfjsdfkjhfiovjalksdhafbvklxkjszjhd";
  return abc.Substring(0, 9);
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Igal Tabachnik
  • 31,174
  • 15
  • 92
  • 157
5
public string test()
{
  string abc="asdhfjsdfkjhfiovjalksdhafbvklxkjszjhd";
  return abc.Substring(0,9);
}
manish
  • 1,450
  • 8
  • 13
4

You can use Substring as answered by others

Other than that

public string test()
{
  string abc = "asdhfjsdfkjhfiovjalksdhafbvklxkjszjhd";
        abc = new string(abc.Take(9).ToArray());
}
Rohit
  • 10,056
  • 7
  • 50
  • 82
3

http://www.dotnetperls.com/substring

you can use this:

public string test()
{
  string abc="asdhfjsdfkjhfiovjalksdhafbvklxkjszjhd";
  abc = abc.Substring(0, 9);
  return abc;
}
Rohit
  • 10,056
  • 7
  • 50
  • 82
Julius R
  • 155
  • 8