Sembra che tu stai chiedendo di una funzione
string Left(string s, int left)
che restituirà i caratteri di sinistra left
della stringa s
. In tal caso puoi semplicemente usare String.Substring
. È possibile scrivere questo come un metodo di estensione:
public static class StringExtensions
{
public static string Left(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
maxLength = Math.Abs(maxLength);
return (value.Length <= maxLength
? value
: value.Substring(0, maxLength)
);
}
}
e usarlo in questo modo:
string left = s.Left(number);
Per esempio specifico:
string s = fac.GetCachedValue("Auto Print Clinical Warnings").ToLower() + " ";
string left = s.Substring(0, 1);
Questa non è una domanda completa- cos'è questa funzione sinistra? Perché stai cercando un'alternativa ad esso? Qual è il tuo input/output previsto? –
Lasciato in Vb.net .. devo convertire questo in C#. Ora ho la risposta tnaks –
Questo non è un duplicato ... l'altra domanda richiede una funzione vb 6 in un programma vb.net. Questa domanda richiede una risposta in C# – Ggalla1779