Remove single quotes

I want to remove single quotes from string as per below example.

Input : 'I am a 'microsoft' developer'

OutPut : I am a microsoft developer


Input : 'Let's play a 'big' Game'

OutPut : Let's play a big Game


Input : 'James' Computer'

OutPut : James' Computer

Please suggest best approach to achieve it.

Thanks.

Answers


here you go

string Input1 = "'I am a 'microsoft' developer'";
string Input2 = "'Let's play a 'big' Game'";

string Result1 = string.Join(" ", Input1.Split(' ').Select(x => x.Trim('\'')));
string Result2 = string.Join(" ", Input2.Split(' ').Select(x => x.Trim('\'')));

i remove every ' which is at the beginning or the end of a word

Update:

as Oliver Nicholls pointed out, there should be some special cases like James'. In this case the ' should be kept. Example:

string Input3 = "'Let's play James' Game'";
string Result3 = string.Join(" ", Input3.Split(' ').Select(x => !x.EndsWith("s'")?x.Trim('\''): x.TrimStart('\'')));

Try this

string origin = "Let's play a 'big' Game";
            string replaced = origin.Replace(" \'", " ").Replace("\' ", " ");

Just remove quotes which are not inside words:

string t = "'Let's play a 'big' Game'";
string[] words = t.Split(' ');
string res = "";
for (int i = 0; i < words.Length; i++)
{
    res += words[i].Trim('\'') + "";

    if ((words.Length - 1) > i)
    {
        res += " ";
    }
}
Console.WriteLine(res);

Need Your Help

GPS stays on although app is moved to background on Android

android gps geolocation react-native

I have a problem with GPS which stays on and keeps polling although my React Native app is moved to background. This is functioning properly on iOS, but on Android nothing happens.