View Single Post
 
Old 01-03-2017, 12:07 AM
MANOHAR MANOHAR is offline Windows 7 32bit Office 2007
Advanced Beginner
 
Join Date: Jan 2017
Posts: 33
MANOHAR is on a distinguished road
Default Spaces inside Fieldcode curly braces

Hello,

We have a application where we have to count the length of the fieldcode text for which we are counting the text inside the InstrText tag which is working fine so far. But we are not able to calculate the fieldcode text of the internal hyperlink field. we using below code snippet to manually build instrText of the hyperlink field.

string HyperlinkFC = string.Empty;
if (element.Attributes().Any(a => a.Name.LocalName == “anchor”))
{
string s = @”HYPERLINK \l”;
HyperlinkFC = string.Format(” {0} \”{1}\” “, s, element.Attribute(W.anchor).Value);
}
fieldCodeText.Append(HyperlinkFC);

Above code is working fine for some cases like below:
{HYPERLINK \l “_Toc165886552”}

But it is failing for some cases where there is a trailing and leading white space inside the curly braces of Hyperlink fieldcode in the begining and end as below

{ HYPERLINK \l “_Toc165886552” }

It is giving 2 characters length difference than expected.

Could someone please tell me how to remove this trailing and leading white space inside curly braces?

Any help will be truly appreiciated!!

Regards,
Manohar
Reply With Quote