none
How to remove the last string from a string seperated by ; a;b;c;d;e;f i want it as a;b;c;d;e RRS feed

  • Question

  • How to remove the last string from a string seperated by ;

    a;b;c;d;e;f

    i want it as 

    a;b;c;d;e

    Wednesday, July 16, 2014 10:39 AM

Answers

  • Hi vivek_kumar9

    What is exactly the porpose of your code? You could simply split your string, take the tokens you need and format them for your required ouptut.

    string input = "a;b;c;d;e;f";
    var tokens = input.Split(';');
    var output = string.Join(";", tokens.Take(tokens.Length - 1));

    Cheers,
    Marc

    • Proposed as answer by Yang,Chenfei Thursday, July 17, 2014 1:57 AM
    • Marked as answer by Yang,Chenfei Wednesday, July 23, 2014 1:18 AM
    Wednesday, July 16, 2014 11:02 AM
  • Hello,

    another solution:

    string input = "a;b;c;d;e;f";

    string newString = input.Substring(0,input.LastIndexOf(';'));

    regards

    • Proposed as answer by Yang,Chenfei Thursday, July 17, 2014 1:57 AM
    • Marked as answer by Yang,Chenfei Wednesday, July 23, 2014 1:18 AM
    Wednesday, July 16, 2014 11:45 AM

All replies

  • Hi vivek_kumar9

    What is exactly the porpose of your code? You could simply split your string, take the tokens you need and format them for your required ouptut.

    string input = "a;b;c;d;e;f";
    var tokens = input.Split(';');
    var output = string.Join(";", tokens.Take(tokens.Length - 1));

    Cheers,
    Marc

    • Proposed as answer by Yang,Chenfei Thursday, July 17, 2014 1:57 AM
    • Marked as answer by Yang,Chenfei Wednesday, July 23, 2014 1:18 AM
    Wednesday, July 16, 2014 11:02 AM
  • Hello,

    another solution:

    string input = "a;b;c;d;e;f";

    string newString = input.Substring(0,input.LastIndexOf(';'));

    regards

    • Proposed as answer by Yang,Chenfei Thursday, July 17, 2014 1:57 AM
    • Marked as answer by Yang,Chenfei Wednesday, July 23, 2014 1:18 AM
    Wednesday, July 16, 2014 11:45 AM