Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have some code that takes a text and splits it up by whatever is within
< p > and < /p >(actually has no spaces but this website wont show it like that)
its pretty simple but it only occurs for the first instance of its occurrence .. I want it to do it for all of the instances of those in the entire text .. this could be done by a loop but I have no idea how to implement the loop

```
var startTag = $"

";
var endTag = $"

";

//For comparison text
//string ImpureCText = "

Hello this is a test to see if this will give an error

hello this could possibly

you are an imbaseel

";// insert text file here
bool b = ImpureCText.Contains(startTag);
bool l = ImpureCText.Contains(endTag);
if (b && l)
{
int index1 = ImpureCText.IndexOf(startTag);
int index2 = ImpureCText.IndexOf(endTag);
if (index1 >= 0) //locates char position of start of pharagraph
Console.WriteLine("'{0} begins at character position {1}", startTag, index1 + 1);
Console.WriteLine("'{0} begins at character position {1}", endTag, index2 + 1);

// This For Pharagraph locate
//string LesserImputerText = Regex.Replace(ImpureTitleText, @"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ").ToString(); //Gets rid of non ASCII values (from http://luisquintanilla.me/2018/01/18/real-time-sentiment-analysis-csharp/) but does seem to do anything when putting non ASCII character such as upsidedown exclamation mark.
int PCstart = ImpureCText.IndexOf(startTag) + startTag.Length; //From here to //this regex breaks it
int PCEnd = ImpureCText.IndexOf(endTag);
string PureText = ImpureCText.Substring(PCstart, PCEnd - PCstart);
Console.WriteLine(PureText);
Console.WriteLine("");

What I have tried:

foreach loops
for loops
looping the entire text - the text between the 2 points in the previous occurrence in the loop so the new text is actually just the old text without that specific string in it . inefficient and no idea how to implement some of the code
Posted
Updated 2-Sep-19 3:58am
v3
Comments
F-ES Sitecore 2-Sep-19 9:03am    
Post the relevant bits of the code you have so far.
HamzaMcBob 2-Sep-19 11:55am    
done it

1 solution

Lets take a look at what you are looking for
C#
startTag = $"<p>";
endTag = $"</p>";
And the items you think should be found
<p1>hello this is a test to see if this works </p1>
<p2>because i feel like this is not going<p2/>
to work now for some horrible reason</p3>
And the comparison values
<p1> Hello this is a test to see if this will give an error</p1>
<p2> hello this could possibly</p2>
<p3> you are an imbaseel</p3>

Conclusion: There are no matches. You are looking for a paragraph element <p> e (look no spaces) but there are none.
You do have <p1>, <p2>, and a (once broken) <p3>

You may want to adjust you code to build "variants" of the sought element.

Or you could use something like the HTML Agility Pack if you are pulling this from an HTML document
 
Share this answer
 
Comments
HamzaMcBob 2-Sep-19 9:56am    
shoo tthat was anerror my pad they should all say
HamzaMcBob 2-Sep-19 9:58am    
updated it now sorry

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900