Line Break Chars and Replaces

I just downloaded 3.1.0 and found that I am getting an error now when I try to do replaces where the data contains line breaks. Is there any way to get this functionality back into Aspose.Word?

The error I am getting is:

An unhandled exception of type ‘System.ArgumentException’ occurred in aspose.word.dll
Additional information: The replace string cannot contain special or break characters.

Just so you know the reason we use this is for dynamic charts that might be in our templates. So we have something like this:

Month Principal Interest
-------------------------------
{REPLACEME}

And the text we replace it with might be:

1 $1000 $50
2 $999 $51
3 $998 $52
4 $997 $53
5 $996 $54
6 $995 $55


Thanks,

John

I will allow to use the line break characters in the next hotfix, sorry for the inconvenience. The reason I disabled it is because in a Word file a line break character has same code as the section break character and Aspose.Word cannot replace or insert paragraph or section breaks.

Sorry, that’s the page break character is the same as section break character.

If you want to insert a line break character, just use ControlChar.LineBreak (that’s “\x000b” or “\v”) instead of paragraph break ("\r"). Inserting paragraph breaks during replace is not yet supported.

romank wrote:
I will allow to use the line break characters in the next hotfix, sorry for the inconvenience. The reason I disabled it is because in a Word file a line break character has same code as the section break character and Aspose.Word cannot replace or insert paragraph or section breaks.


Which versions of Aspose.Word allow line breaks in the replace string in the Replace method of the Range object?

Thanks,
-Brian

Hi Brian,

The latest version surely supports that, please download and install it.

DmitryV wrote:

Hi Brian,

The latest version surely supports that, please download and install it.



Sorry, I should have been clearer. I wanted to use the Replace method of the Range class to find a string and replace it with another string that includes a carriage return. With the latest version of Aspose.Word this is broken and throws an exception that talks about not allowing special characters or line breaks in the replacing string.

I downgraded to an unknown older version (2.4.0) that I found on my hard drive and my code works again. Since this was apparently broken in a recent version (I tried 3.2, I think) will this be unbroken in a future release?

Thanks,
-Brian

Carriage return (0x0d) and line break (0x0b) characters are not the same. Carriage return is equivalent to paragraph break, not line break. Line breaks are allowed to be included into a replacement string in the recent versions so you can use it, or exactly paragraph breaks are required?

DmitryV wrote:
Carriage return (0x0d) and line break (0x0b) characters are not the same. Carriage return is equivalent to paragraph break, not line break. Line breaks are allowed to be included into a replacement string in the recent versions so you can use it, or exactly paragraph breaks are required?


When I insert a string with only line breaks ("foo" & chr(10) & "bar") or a combined line break and carriage return ("foo" & chr(13) & chr(10) & "bar") it ends up rendering the 0x0b as a square.

How should I use a single linebreak so that it renders as a return between my "foo" and "bar".

This is in VB.Net, btw.

Thanks,
-Brian

Probably just use ControlChar.LineBreak. The following test case works fine for me:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("foo bar");

doc.Range.Replace("foo bar", "foo" + ControlChar.LineBreak + "bar", false, false);