本文整理汇总了C#中ITsString.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.Substring方法的具体用法?C# ITsString.Substring怎么用?C# ITsString.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITsString
的用法示例。
在下文中一共展示了ITsString.Substring方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAnalyses
/// ------------------------------------------------------------------------------------
/// <summary>
/// Creates analyses for the words and punctuation forms of the specified segment. Words
/// will have WfiWordforms created if they don't already exist.
/// </summary>
/// <param name="segment">The segment.</param>
/// <param name="paraContents">The para contents.</param>
/// <param name="ichBeginOffset">The beginning character offset.</param>
/// <param name="ichLimOffset">The character offset limit.</param>
/// <param name="fCreateGlosses">if set to <c>true</c> create glosses in addition to the
/// WfiWordforms for each surface form.</param>
/// ------------------------------------------------------------------------------------
public static void CreateAnalyses(ISegment segment, ITsString paraContents,
int ichBeginOffset, int ichLimOffset, bool fCreateGlosses)
{
FdoCache cache = segment.Cache;
IFdoServiceLocator servloc = cache.ServiceLocator;
if (SegmentBreaker.HasLabelText(paraContents, ichBeginOffset, ichLimOffset))
{
IPunctuationForm labelPunc = servloc.GetInstance<IPunctuationFormFactory>().Create();
segment.AnalysesRS.Add(labelPunc);
labelPunc.Form = paraContents.GetSubstring(ichBeginOffset, ichLimOffset);
}
else
{
ParseSegBaseline(segment, ichBeginOffset, ichLimOffset, (iForm, word, iAnalysis) =>
{
CreateAnalysisForWord(word, segment, cache.DefaultAnalWs, fCreateGlosses);
return true;
},
(sPunc, iAnalysis) => CreatePuncForm(segment, cache.TsStrFactory.MakeString(sPunc, cache.DefaultVernWs)),
(ichOrc, iAnalysis) => CreatePuncForm(segment, paraContents.Substring(segment.BeginOffset + ichOrc, 1)));
}
}
示例2: TrimNonWordFormingChars
/// ------------------------------------------------------------------------------------
/// <summary>
/// Trim the leading AND/OR trailing non-word forming characters.
/// </summary>
/// <param name="tssInput">string that may contain non-word forming characters</param>
/// <param name="writingSystemFactory">The ws factory used to get character properties</param>
/// <param name="fTrimLeading">if set to <c>true</c> trim leading characters.</param>
/// <param name="fTrimTrailing">if set to <c>true</c> trim trailing characters.</param>
/// <returns>
/// string with leading or trailing non-word forming characters trimmed
/// </returns>
/// ------------------------------------------------------------------------------------
public static ITsString TrimNonWordFormingChars(ITsString tssInput, ILgWritingSystemFactory writingSystemFactory, bool fTrimLeading, bool fTrimTrailing)
{
Debug.Assert(fTrimLeading || fTrimTrailing);
if (tssInput == null)
return null;
string untrimmedString = tssInput.Text;
if (String.IsNullOrEmpty(untrimmedString))
return tssInput;
ILgCharacterPropertyEngine charProps = null;
int ichMin;
bool fFoundWordFormingChar = false;
if (fTrimLeading)
{
// Trim leading non-word forming characters from string.
ichMin = -1;
for (int ich = 0; ich < untrimmedString.Length; ich++)
{
charProps = GetCharPropEngineAtOffset(tssInput, writingSystemFactory, ich);
if (charProps != null && charProps.get_IsWordForming(untrimmedString[ich]))
{
// first word-forming character found
ichMin = ich;
fFoundWordFormingChar = true;
break;
}
}
if (ichMin == -1)
return MakeTss("", GetWsAtOffset(tssInput, 0));
// no word-forming characters found in the string
}
else
ichMin = 0;
int strLength;
if (fTrimTrailing)
{
// Trim trailing non-word forming characters from string.
strLength = 1;
int iMin = (ichMin == 0) ? -1 : ichMin;
for (int ich = untrimmedString.Length - 1; ich > iMin; ich--)
{
charProps = GetCharPropEngineAtOffset(tssInput, writingSystemFactory, ich);
if (charProps != null && charProps.get_IsWordForming(untrimmedString[ich]))
{
// last word-forming character found
strLength = ich - ichMin + 1;
fFoundWordFormingChar = true;
break;
}
}
if (!fFoundWordFormingChar)
return MakeTss("", GetWsAtOffset(tssInput, 0));
// no word-forming characters found in the string
}
else
strLength = untrimmedString.Length - ichMin;
return tssInput.Substring(ichMin, strLength);
}
示例3: Split
/// ------------------------------------------------------------------------------------
/// <summary>
/// Split the ITsString into pieces separated by one of the strings in separator, and
/// using the same options as String.Split().
/// </summary>
/// ------------------------------------------------------------------------------------
public static List<ITsString> Split(ITsString tss, string[] separator, StringSplitOptions opt)
{
List<ITsString> rgtss = new List<ITsString>();
if (tss == null || tss.Length == 0 || separator == null || separator.Length == 0)
{
rgtss.Add(tss);
}
else
{
int ich = 0;
while (ich < tss.Length)
{
int cchMatch = 0;
int ichEnd = tss.Text.IndexOf(separator[0], ich);
if (ichEnd < 0)
ichEnd = tss.Length;
else
cchMatch = separator[0].Length;
for (int i = 1; i < separator.Length; ++i)
{
int ichEnd2 = tss.Text.IndexOf(separator[i], ich);
if (ichEnd2 < 0)
ichEnd2 = tss.Length;
if (ichEnd2 < ichEnd)
{
ichEnd = ichEnd2;
cchMatch = separator[i].Length;
}
}
int length = ichEnd - ich;
if (length > 0 || opt == StringSplitOptions.None)
rgtss.Add(tss.Substring(ich, length));
ich = ichEnd + cchMatch;
}
}
return rgtss;
}