Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vance 5 posts 63 karma points
    Jul 15, 2014 @ 19:10
    Vance
    0

    punctuation issue with (node name)string

    Currently,i am working on search feature.

    i am using POST method to get user data.

    as a ex :

    Restaurant name in umbraco backend : Pico's

    user search string (SearchStr) : picos

    resule will come out : No match found bcz of punctuation issue.

    i created cshtml file for backend coding.

     

    e.g.

    foreach (var node in startNode.Children.Where("Visible"))

    {

     CurrentNode = node.Name;

     CurrentNode2 = CurrentNode.ToLower();

     CurrentIndex = CurrentNode2.IndexOf(searchStr.ToLower());

     

    if (CurrentIndex != -1)

     { 

    -------

    /* my code */

    }

     

    can you tell me the best way to remove punctuation from my node name ??

    Thank you for your help !!

     

    -Vance

  • Damien Green 72 posts 134 karma points
    Jul 16, 2014 @ 19:06
    Damien Green
    100

    Hi Vance,

    You could try

    if (CurrentNode2.ToLower().Contains(searchStr.ToLower()) { ...... }

    But I have a feeling it has to make a match on the exact string in a direct sequence (I'm away from home with just an iPad so can't test stuff here)

    Which should work but might not be robust in circumstances where perhaps the name of one restaurant is contained within the name of another.

    If you simply want to remove the ' character from your string. A simple way would be to do CurrentNode2 = CurrentNode2.Replace("'","");. Of course that will only string out the ' characters so probably isn't appropriate.

    I sense here that you actually need to do more than just filter out the punctuation, you actually want to write some sort of algorithm that returns a result based on best match. Unfortunately demonstration code for that is probably out of the scope of an answer on this forum, but I would think along the lines of maybe converting the search and mode name to Unicode character numbers. You can do this by casting each character to a char and then hard-casting the char to an int. You can then do a character by character comparison of the two strings and generate a percentage match based on numbers of characters successfully matched. You could then take the user to the page that returns the highest percent match.

    This would be a very simplistic system and would certainly be better improved with features such recording the length of string match etc. to add extra weight to the probability match calculation. As you're probably beginning to see a match system can be quite complex and there may even be .net source code examples out there to help you on your way.

    Hope this helps,

    Cheers,

    Damien

  • Vance 5 posts 63 karma points
    Jul 16, 2014 @ 21:40
    Vance
    0

    Hey Damien,

    Thank you for your help !! :)


     


  • Damien Green 72 posts 134 karma points
    Jul 16, 2014 @ 22:09
    Damien Green
    0

    Hey no problem, happy to help!

    Good luck, if you're still having problems when I'm back next week give me a shout and I'll see if I can come up with some rudimentary code for you.

    Cheers,

    Damien

Please Sign in or register to post replies

Write your reply to:

Draft