我想将此VB
代码转换为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
我试过下面的代码,
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");
}
但是,现在我在
Strings.Right
,Strings.Trim
和Paragraph[hNumb].Style
收到错误public interface IService1: IDisposable { IEnumerable<SomeDataType> GetSomeData(string param); void SaveData(); } public class Service1: IService1 { private MyContext context; public Maestri(MyContext context) { this.context = context; } public void Dispose() { context.Dispose(); } public IEnumerable<SomeDataType> GetSomeData(string Param) { [...] } public void SaveData() { [...] context.SaveChanges() } } public interface IService2: IDisposable { IEnumerable<SomeDataType2> GetSomeData(string param); void SaveData(); } public class Service2: IService2 { private MyContext context; public Maestri(MyContext context) { this.context = context; } public void Dispose() { context.Dispose(); } public IEnumerable<SomeDataType2> GetSomeData(string Param) { [...] } public void SaveData() { [...] context.SaveChanges() } }
。这里的风格属性不存在。这三个 地方错误即将来临。
请帮帮我......
答案 0 :(得分:2)
试试这个
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
我无法尝试使用此代码,因为我没有使用您正在使用的库,但这可以让您了解如何转换该代码..
如果您还有其他问题,请随时提出。
答案 1 :(得分:1)
你能试试吗?
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");
}
答案 2 :(得分:1)
请尝试以下操作:
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");
}