我有这个文字。</ul>
标记之前有一个新行。所以我无法使用此代码删除该行。
str = str.Replace(Environment.NewLine,"");
但是这段代码只适用于通常的字符串。
<ul style="list-style-type:circle;">
<li><a class="ms - wikilink" href="/Test.aspx">Test1</a></li>
</ul>
答案 0 :(得分:6)
您可以使用Regex轻松删除它
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/admin/login.htm"/>
<property name="successUrl" value="/admin/index.htm"/>
<!-- override these for application-specific URLs if you like:
<property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
<!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean -->
<!-- defined will be automatically acquired and available via its beanName in chain -->
<!-- definitions, but you can perform instance overrides or name aliases here if you like: -->
<!-- <property name="filters">
<util:map>
<entry key="anAlias" value-ref="someFilter"/>
</util:map>
</property> -->
<property name="filterChainDefinitions">
<value>
/admin/** = authc, roles[admin]
/logout.htm = logout
# some example chain definitions:
#/docs/** = authc, perms[document:read]
#/** = authc
# more URL-to-FilterChain definitions here
</value>
</property>
</bean>
<!-- Define any javax.servlet.Filter beans you want anywhere in this application context. -->
<!-- They will automatically be acquired by the 'shiroFilter' bean above and made available -->
<!-- to the 'filterChainDefinitions' property. Or you can manually/explicitly add them -->
<!-- to the shiroFilter's 'filters' Map if desired. See its JavaDoc for more details. -->
<!--<bean id="someFilter" class="..."/>
<bean id="anotherFilter" class="..."> ... </bean>
-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
<property name="realm" ref="myRealm"/>
<property name="cacheManager" ref="cacheManager"/>
<!-- By default the servlet container sessions will be used. Uncomment this line
to use shiro's native sessions (see the JavaDoc for more): -->
<!-- <property name="sessionMode" value="native"/> -->
</bean>
<bean id="stormpathClient" class="com.stormpath.shiro.client.ClientFactory">
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
<property name="cacheManager" ref="cacheManager"/>
<property name="apiKeyFileLocation" value="$HOME/.stormpath/apiKey.properties"/>
<!-- By default the servlet container sessions will be used. Uncomment this line
to use shiro's native sessions (see the JavaDoc for more): -->
<!-- <property name="sessionMode" value="native"/> -->
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Define the Shiro Realm implementation you want to use to connect to your back-end -->
<!-- security datasource: -->
<bean id="myRealm" class="com.stormpath.shiro.realm.ApplicationRealm">
<property name="applicationRestUrl" value="https://api.stormpath.com/v1/applications/<my app key here removed for privacy>"/>
<property name="client" ref="stormpathClient"/>
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
我希望它有所帮助!
答案 1 :(得分:2)
这可能会为你做到这一点
var regex = new Regex(@"(?<=>)\s+?(?=<)", RegexOptions.Multiline);
var outstr = regex.Replace(YourHTMLString,"");
答案 2 :(得分:1)
您可以查找以下方案
^$
- 查找任何开始和结束(没有字符)或
^\s+$
- 查找任何开头的行,有空格,结束
寻找多个多次查找
(^$|^\s+$)
- ()群组,|允许搜索中的OR语句
Regex.Replace(content, @"(^$|^\s+$)", String.Empty);
- 请注意我的C#生锈了,请确保在正则表达式中启用多行搜索(通常是/m
)