FieldGetFieldCode Method (Boolean)
Returns text between field start and field separator (or field end if there is no separator).

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public string GetFieldCode(
	bool includeChildFieldCodes
)

Parameters

includeChildFieldCodes
Type: SystemBoolean
True if child field codes should be included.

Return Value

Type: String
Examples
Shows how to get text between field start and field separator (or field end if there is no separator)
Document doc = new Document(MyDir + "Field.FieldCode.docx");

foreach (Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldIf)
    {
        FieldIf fieldIf = (FieldIf)field;

        string fieldCode = fieldIf.GetFieldCode();
        Assert.AreEqual(
            " IF " + ControlChar.FieldStartChar + " MERGEFIELD Q223 " + ControlChar.FieldSeparatorChar + ControlChar.FieldEndChar + " > 0 \" (and additionally London Weighting of  " + ControlChar.FieldStartChar + " MERGEFIELD  Q223 \\f £ " + ControlChar.FieldSeparatorChar + ControlChar.FieldEndChar + " per hour) \" \"\" ",

        if (containsNestedFields)
        {
            fieldCode = fieldIf.GetFieldCode(true);
            Assert.AreEqual(
                " IF " + ControlChar.FieldStartChar + " MERGEFIELD Q223 " + ControlChar.FieldSeparatorChar + ControlChar.FieldEndChar + " > 0 \" (and additionally London Weighting of  " + ControlChar.FieldStartChar + " MERGEFIELD  Q223 \\f £ " + ControlChar.FieldSeparatorChar + ControlChar.FieldEndChar + " per hour) \" \"\" ",
        }
        else
        {
            fieldCode = fieldIf.GetFieldCode(false);
            Assert.AreEqual(" IF  > 0 \" (and additionally London Weighting of   per hour) \" \"\" ",
        }
    }
}
See Also