locked
Input the joint string and output the string with spaces in between character in string RRS feed

  • Question

  • User-1317453444 posted

    Suppose I input joint characters string as string parameter to the function, like for eg 'howareyou' or 'youarewelcome' it should revert me back with 'how are you', 'you are welcome'. I am having the dictionary of words like {'how', 'you', 'welcome', 'are'}. Then how would you do it ?

    Monday, November 6, 2017 1:48 PM

Answers

All replies

  • User347430248 posted

    Hi nelsonrock10...,

    if you just save the 'youarewelcome' or 'howareyou' in field then there is no way to add space between words.

    because SQL does not know that where the space should be inserted.

    so you can try to add "|" or any other special character  in your dictionary after the end of each word.

    so we can replace it with space.

    something like below.

    Query:

    SELECT REPLACE(str, '|', ' ') from Table_1;

    Output:

    same thing you can done in procedure.

    Regards

    Deepak

    Tuesday, November 7, 2017 3:18 AM
  • User-1317453444 posted

    For that dictionary of words like {'how', 'you', 'welcome', 'are'} are provided. Are you still not cleared then pl let me know.

    Tuesday, November 7, 2017 5:09 AM
  • User2103319870 posted

    Suppose I input joint characters string as string parameter to the function, like for eg 'howareyou' or 'youarewelcome' it should revert me back with 'how are you', 'you are welcome'. I am having the dictionary of words like {'how', 'you', 'welcome', 'are'}. Then how would you do it ?

    You can create a class namely "WordSplitter" in your solution and then use the code provided in this thread How to add spaces between words in a spaceless strings

    Then you can use the WordSplitter to add space based on words in dictionary.

    Sample code to call the method

                string[] dictionary = new string[5] { "how", "you", "welcome", "are", "has" };
                WordSplitter WS = new WordSplitter(dictionary);
                string test = WS.SplitToWords("howareyou".ToLower());

     

    Tuesday, November 7, 2017 5:22 AM
  • User-1317453444 posted

    Hi a2h,

    there is no string method as SplitToWords, can you pl provide me illustration of the classes too.

    Regards,

    Tuesday, November 7, 2017 6:03 AM
  • User2103319870 posted

    can you pl provide me illustration of the classes too.

    You can find the code from this link How to add spaces between words in a spaceless strings

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 7, 2017 6:13 AM