Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.NET中解析字符串?_Asp.net - Fatal编程技术网

如何在ASP.NET中解析字符串?

如何在ASP.NET中解析字符串?,asp.net,Asp.net,我需要分析一个句子。 如果我在句子中发现一个散列,我想加粗 示例:Bonjour#helloHi=>Bonjour#helloHi可能有一种更优雅的方法来实现这一点,但您可以使用该方法来查找哈希的第一个实例,如下所示 String myString = "Bonjour #hello hi"; int index = myString.IndexOf('#'); if(index>-1) //IndexOf returns -1 if the character isn't found {

我需要分析一个句子。 如果我在句子中发现一个散列,我想加粗


示例:Bonjour
#hello
Hi=>Bonjour#helloHi

可能有一种更优雅的方法来实现这一点,但您可以使用该方法来查找哈希的第一个实例,如下所示

String myString = "Bonjour #hello hi";
int index = myString.IndexOf('#');
if(index>-1) //IndexOf returns -1 if the character isn't found
{
  //search for the next space after the hash
  int endIndex=mystring.IndexOf(' ',index+1)
  myString=MakeBold(myString,index,endIndex);
}

剩下的就是实现MakeBold函数。

对于正则表达式来说似乎是一个好情况

我会这样做

boldHashes("Bonjour #hello Hi");

...

private string boldHashes(string str)
{
    return Regex.Replace(str, @"(#\w+)", "<strong>$1</strong>");
}
jQuery

$('#myDiv').html($('#myDiv').text().replace(/(#\w+)/g, '<strong>$1</strong>'));
$('myDiv').html($('myDiv').text().replace(/('myDiv+)/g,$1);

可能属于StackOverflow,并将您尝试的代码与问题一起发布。此外,您可能希望扩展函数以考虑字符串中的多个哈希。是否可以在视图中使用它?因为我需要它在html中。因为我想在不使用
的情况下保存此字符串,如何使用jQuery执行相同的操作?请
$('#myDiv').html($('#myDiv').text().replace(/(#\w+)/g, '<strong>$1</strong>'));