Function for Converting Plural into Singular
-
Hi all, I am trying to write a function which converts plural words into singular words. Below is the function which i have created but it is not working properly for the words which ends with -se like lease, prise etc. Means when it comes to conver these words from plural to singular it is not giving proper output.It is converting "Leases" to "Leas" and "phrases" to "Phras". Please help me as soon as possible! private void _StripPlural(string strValue) { if (strValue.Length > 1) { if (strValue.EndsWith("s")) { strValue = strValue.Substring(0, strValue.Length - 1); string strPluralRule="s,z,x,ch,sh,ss"; bool blnFlag = false; char[] arrchDelimeter ={ ',' }; string[] arrstr = strPluralRule.Split(arrchDelimeter); for (int i = 0; i < arrstr.Length; i++) { string strTest = arrstr[i] + "e"; if (strValue.EndsWith(strTest) && !strValue.EndsWith("sse")) { blnFlag=true; return; } } if (blnFlag == true) { strValue = strValue.Substring(0, strValue.Length - 1); } if (strValue.EndsWith("ie")) { strValue = strValue.Substring(0, strValue.Length - 2) + "y"; } if (strValue.EndsWith("sse")) { strValue = strValue.Substring(0, strValue.Length - 1); } } } //return strValue; } Regards,
-
Hi all, I am trying to write a function which converts plural words into singular words. Below is the function which i have created but it is not working properly for the words which ends with -se like lease, prise etc. Means when it comes to conver these words from plural to singular it is not giving proper output.It is converting "Leases" to "Leas" and "phrases" to "Phras". Please help me as soon as possible! private void _StripPlural(string strValue) { if (strValue.Length > 1) { if (strValue.EndsWith("s")) { strValue = strValue.Substring(0, strValue.Length - 1); string strPluralRule="s,z,x,ch,sh,ss"; bool blnFlag = false; char[] arrchDelimeter ={ ',' }; string[] arrstr = strPluralRule.Split(arrchDelimeter); for (int i = 0; i < arrstr.Length; i++) { string strTest = arrstr[i] + "e"; if (strValue.EndsWith(strTest) && !strValue.EndsWith("sse")) { blnFlag=true; return; } } if (blnFlag == true) { strValue = strValue.Substring(0, strValue.Length - 1); } if (strValue.EndsWith("ie")) { strValue = strValue.Substring(0, strValue.Length - 2) + "y"; } if (strValue.EndsWith("sse")) { strValue = strValue.Substring(0, strValue.Length - 1); } } } //return strValue; } Regards,
KBM73 wrote:
string[] arrstr = strPluralRule.Split(arrchDelimeter);
That will eat your delimiters, how will you add it again? You will have to think of another way :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4 out now (27 May 2008) -
KBM73 wrote:
string[] arrstr = strPluralRule.Split(arrchDelimeter);
That will eat your delimiters, how will you add it again? You will have to think of another way :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4 out now (27 May 2008) -
Hi all, I am trying to write a function which converts plural words into singular words. Below is the function which i have created but it is not working properly for the words which ends with -se like lease, prise etc. Means when it comes to conver these words from plural to singular it is not giving proper output.It is converting "Leases" to "Leas" and "phrases" to "Phras". Please help me as soon as possible! private void _StripPlural(string strValue) { if (strValue.Length > 1) { if (strValue.EndsWith("s")) { strValue = strValue.Substring(0, strValue.Length - 1); string strPluralRule="s,z,x,ch,sh,ss"; bool blnFlag = false; char[] arrchDelimeter ={ ',' }; string[] arrstr = strPluralRule.Split(arrchDelimeter); for (int i = 0; i < arrstr.Length; i++) { string strTest = arrstr[i] + "e"; if (strValue.EndsWith(strTest) && !strValue.EndsWith("sse")) { blnFlag=true; return; } } if (blnFlag == true) { strValue = strValue.Substring(0, strValue.Length - 1); } if (strValue.EndsWith("ie")) { strValue = strValue.Substring(0, strValue.Length - 2) + "y"; } if (strValue.EndsWith("sse")) { strValue = strValue.Substring(0, strValue.Length - 1); } } } //return strValue; } Regards,