如何修剪字符串并显示特定部分 [英] How to trim a string and display particular part
本文介绍了如何修剪字符串并显示特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
以下是我得到的字符串
发生了一个或多个警告。建议您按照提供的
说明更正问题,然后再试一次。
--------------- - - - - - - - - - - 信息 - - - - - - - - - - - - - - - -----
控制站:检查待机是否已启动
信息HC_CS_27389984778:备用控制站当前已开启
。升级期间将关闭电源,然后
后来重新启动并升级。
---------------------------------------- ----------------------------------------
------ ------------------------------警告------------------- -----------------
刀片:检查病毒检查程序服务器配置
警告HC_DM_18800115743:
* vnxdm01:病毒检查程序配置只包含一个病毒
Checker(VC)服务器。高可用性受到损害。建议至少添加
一个新的VC服务器。
操作:使用EMC Celerra AntiVirus MMC在病毒检查程序配置中添加新的VC服务器
,或手动编辑配置
文件。
---------------------------------------------- ----------------------------------
i想要这个
---------------- --------------------警告----------------------------- -------
刀片:检查病毒检查程序服务器配置
警告HC_DM_18800115743:
* vnxdm01:病毒检查程序配置只包含一个Virus
Checker(VC)服务器。高可用性受到损害。建议至少添加新的VC服务器
。
操作:使用EMC Celerra AntiVirus MMC在病毒检查程序配置中添加新的VC服务器
,或者手动编辑配置
文件。
------------------------------------ --------------------------------------------
请让我知道怎么做
解决方案
使用正则表达式:
- +警告 - + [^ - ] + - +应该这样做。
'Warnings'
行,然后在结果字符串中包含所有剩余部分。
例如
public static string mytrim( string ins)
{
string [] line = ins.Split( new char [] {' \ n'}); // 获取行数
int n;
for (n = 0 ; n< line.Length; ++ n)
{
if (line [n] .Contains( - 警告 - )) // 搜索警告行
break ;
}
StringBuilder sb = new StringBuilder();
for (; n < line.Length; ++ n) // 使用剩余的(可能为空的)部分来构建结果字符串
{
sb。追加(行[N]);
sb.Append( \ n);
}
return sb.ToString();
}
Hi all
Below is the string i am getting
"One or more warnings have occurred. It is recommended that you follow the
instructions provided to correct the problem then try again.
-----------------------------------Information----------------------------------
Control Station: Check if standby is up
Information HC_CS_27389984778: The standby Control Station is
currently powered on. It will be powered off during upgrade, and then
later restarted and upgraded.
--------------------------------------------------------------------------------
------------------------------------Warnings------------------------------------
Blades : Check virus checker server configuration
Warning HC_DM_18800115743:
* vnxdm01: The virus checker configuration contains only one Virus
Checker (VC) server. High availability is compromised. It is
recommended to add at least a new VC server.
Action : Use the EMC Celerra AntiVirus MMC to add a new VC server
in the virus checker configuration, or edit the configuration
file manually.
--------------------------------------------------------------------------------"
i want this
------------------------------------Warnings------------------------------------
Blades : Check virus checker server configuration
Warning HC_DM_18800115743:
* vnxdm01: The virus checker configuration contains only one Virus
Checker (VC) server. High availability is compromised. It is
recommended to add at least a new VC server.
Action : Use the EMC Celerra AntiVirus MMC to add a new VC server
in the virus checker configuration, or edit the configuration
file manually.
--------------------------------------------------------------------------------"
Please let me know how to do this
解决方案
Use a regex:
-+Warnings-+[^-]+-+Should do it.
Following the example, a simple approach would be searching for the'Warnings'
line and then include in your result string all the remaining part.
e.g.
public static string mytrim(string ins) { string[] line = ins.Split(new char[] { '\n' }); // obtain an array of lines int n; for (n=0; n<line.Length; ++n) { if (line[n].Contains("-Warnings-")) // search for the 'Warnings' line break; } StringBuilder sb = new StringBuilder(); for (; n < line.Length; ++n) // use the remaining (possibly empty) part for building the result string { sb.Append(line[n]); sb.Append("\n"); } return sb.ToString(); }
这篇关于如何修剪字符串并显示特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文