Reputation: 493
I want to convert this VB
code to C#
.
If Right(Trim(ActiveDocument.Bookmarks("\HeadingLevel").Range.Paragraphs(hNumb).Style), 6) = "NoNumb" Then
h_prefix = sGetDocVar("CTDPrefix")
SetDocVar "TablePrefix", "Table " & h_prefix & "."
t_prefix = sGetDocVar("TablePrefix")
hNumb = "-"
Else
h_prefix = sGetDocVar("CTDPrefix")
SetDocVar "TablePrefix", "Table " & h_prefix & "."
t_prefix = sGetDocVar("TablePrefix")
End If
I have tried below code,
if (Strings.Right(Strings.Trim(ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style), 6) == "NoNumb") {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar("TablePrefix", "Table " + h_prefix + ".");
t_prefix = sGetDocVar("TablePrefix");
hNumb = "-";
} else {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar("TablePrefix", "Table " + h_prefix + ".");
t_prefix = sGetDocVar("TablePrefix");
}
But, now I am getting error in
Strings.Right
,Strings.Trim
andParagraph[hNumb].Style
. Here style property not there. These three place error is coming.
Please help me...
Upvotes: 0
Views: 88
Reputation: 34421
Try following :
string bookMark = ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.ToString();
if (bookMark.Trim() == "NoNumb") {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar("TablePrefix", "Table " + h_prefix + ".");
t_prefix = sGetDocVar("TablePrefix");
hNumb = "-";
} else {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar("TablePrefix", "Table " + h_prefix + ".");
t_prefix = sGetDocVar("TablePrefix");
}
Upvotes: 1
Reputation: 7095
try like this
var style = ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs[hNumb].Style;
var styleString = style.ToString().Trim();
if (styleString.Length >= 6 && styleString.Substring(style.Length - 6) == "NoNumb")
{
//rest of your code
I cannot try this code because I don't have that libraries you're using, but this should give you an idea how to convert that code..
If you have additional questions, feel free to ask.
Upvotes: 2
Reputation: 905
Can you try this?
if ((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Substring((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Length - 6)) == "NoNumb")) {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar;
"TablePrefix";
("Table "
+ (h_prefix + "."));
t_prefix = sGetDocVar("TablePrefix");
hNumb = "-";
}
else {
h_prefix = sGetDocVar("CTDPrefix");
SetDocVar;
"TablePrefix";
("Table "
+ (h_prefix + "."));
t_prefix = sGetDocVar("TablePrefix");
}
Upvotes: 1