我正在尝试拆分这样的XML字符串,
"<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph Margin="0,0,0,0"><Span><Run>This is to test a split page function</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"><Span><Run>PAGE_BREAK</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"><Span><Run>This is page two</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph><Run></Run></Paragraph></Section>"
使用&#34; PAGE_BREAK&#34;在字符串中 - 并且本来希望它分成两个数组,而是它将它分成18个。任何想法我在这里做错了吗?
Dim IsPageBreak As Boolean = False
Dim vPages() As String = Nothing
Dim vPageNumbers As Integer = 0
If Letter_String.Contains("PAGE_BREAK") Then
vPages = Letter_String.Split("PAGE_BREAK")
vPageNumbers = vPages.Length
IsPageBreak = True
End If
答案 0 :(得分:1)
不知道你为什么要这样做,但这会得到你想要的结果。
Dim xe As XElement
xe = <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0">
<Paragraph Margin="0,0,0,0">
<Span>
<Run>This is to test a split page function</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0">
<Span>
<Run>PAGE_BREAK</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0">
<Span>
<Run>This is page two</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph><Run></Run></Paragraph>
</Section>
Dim vPages() As String = Strings.Split(xe.ToString, "PAGE_BREAK")