在最后一个特殊字符后删除Char

时间:2017-06-22 09:34:32

标签: c# char

嗨我有一个像这样的字符串

string str="user1,user2,user3,user4,user5,user6";

我想在最后,删除所有字符串,然后str变为user6。 我该怎么做才能使用c#

2 个答案:

答案 0 :(得分:4)

尝试:

var Code = new Array();
window.onload = function(e){     
   Code = new Array("", getHTMLContent("fwelcome_content"), getHTMLContent("fbilling_content"), getHTMLContent("freply_content"), getHTMLContent("fdelivery_content"));
}
function change() {
  var ID = formconteudo.message.options[formconteudo.message.selectedIndex].value;
  CKEDITOR.instances.editor1.setData('<p>' + Code[ID] + '</p>');
}
function getHTMLContent(elementId){
  var htmlContent = document.getElementsByName(elementId)[0].innerHTML;
  document.getElementsByName(elementId)[0].remove();
  return htmlContent;
}

或添加string newStr = str.Substring(str.LastIndexOf(",") + 1)); 并使用:

using System.Linq;

答案 1 :(得分:0)

可以使用Linq完成如下操作。

string Result
    = str.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries).Last();
相关问题