Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Following is the standard convention to note while creating new fields in Hawksearch:

  1. Only alphanumeric characters and the underscore are allowed in the fieldname

  2. All characters are lowercase

  3. Spaces must be replaced by underscores '_'

  4. Underscore cannot be at the beginning or end of the name

  5. Atleast one character is required

  6. Atleast one number is required - an ā€œnā€ will be appended to it


C# code block for your reference as below:

public static string GetStandardFieldName(string InputField)
{
    var rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9_]");

    string SField = InputField;
    SField = SField.Replace(" ", "_");
    SField = rgx.Replace(SField, "");

    if (!string.IsNullOrEmpty(SField))
    {
        SField = SField.ToLower();
        if (SField.StartsWith("_"))
            SField = SField.Remove(0, 1);
        if (SField.EndsWith("_"))
            SField = SField.Remove(SField.Length - 1);
    }

    if (!string.IsNullOrEmpty(SField))
    {
        if(int.TryParse(SField.Substring(0, 1), out int result))
            SField= "n" + SField;
    }

    return SField;
}


Examples:

GetStandardFieldName("Hello, world!") 
GetStandardFieldName("99Hello, world!") 
GetStandardFieldName("_1Hello, world!_")

Outputs:

hello_world
n99hello_world
n1hello_world

  • No labels