+ Reply to Thread
Results 1 to 8 of 8

find position of special characters in string

  1. #1
    Registered User
    Join Date
    06-12-2009
    Location
    KOndur
    MS-Off Ver
    Excel 2003
    Posts
    3

    find position of special characters in string

    Dear community members,

    I hope that you'll help me with what I'm trying to accomplish.
    There is string in my worksheet cells which is comprised of English letters,numbers and greek (mostly the Phi) letters and most of these strings in cells are in same format. I want to parse out that string to special characters so I can find what is before,after and between these special characters.


    For exmaple
    The search string e.g. name = "15(Phi)12/15 L=315" ' Need to find the position of (Phi) and "slash" so I can retrieve the "12"
    To find that I'm using the folowing code

    Please Login or Register  to view this content.
    While debugging I get "pos" assigned to 2 and "pos_slash" to 6 and phi variable assigned to "5F12/1", position of pos_slash is correct in that case but "pos =2" is not. I think that the problem with this string is mixed with unicode and ANSI characters, but still don't know how to figure it out?

    Help in advance will be appreciated.
    Regards,
    Last edited by DonkeyOte; 06-14-2009 at 02:47 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: find position of special characters in string

    Both your values are correct...

    pos returns 2 because you're using 0 bound (ie 0 = 1, 1 = 2 etc...)

    That said I suspect you could probably simplify your code to a line like:

    Please Login or Register  to view this content.
    which would return 12.

  3. #3
    Registered User
    Join Date
    06-12-2009
    Location
    KOndur
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: find position of special characters in string

    Quote Originally Posted by DonkeyOte View Post
    Both your values are correct...

    pos returns 2 because you're using 0 bound (ie 0 = 1, 1 = 2 etc...)

    That said I suspect you could probably simplify your code to a line like:

    Please Login or Register  to view this content.
    which would return 12.
    Sorry but I couldn't get that worked, what should I put into that "Phi character" argument original Greek letter Phi or Unicode equivalent?

    What does that (1) means out of scope Split function ?

    Regards,

  4. #4
    Registered User
    Join Date
    06-12-2009
    Location
    KOndur
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: find position of special characters in string

    I couldn't succed that to work Any help please?

  5. #5
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: find position of special characters in string

    I assumed your data entered in cell A1 (A1="15(Phi)12/15 L=315")
    So,

    if you want to specify "(Phi)", you could use the long formula like this:
    PHP Code: 
    =VALUE(MID(SUBSTITUTE(A1,"(Phi)","#"),FIND("#",SUBSTITUTE(A1,"(Phi)","#"))+1,FIND("/",SUBSTITUTE(A1,"(Phi)","#"))-FIND("#",SUBSTITUTE(A1,"(Phi)","#"))-1)) 

    OR
    if not, I mean you focus on ")", you could use the shorter formula like this:
    PHP Code: 
    =VALUE(MID(A1,FIND(")",A1)+1,FIND("/",A1)-FIND(")",A1)-1)) 

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,570

    Re: find position of special characters in string

    observed: my short experiment gave codes 70 & 83 for upper and lower case phi , also since your array bounds are zero based, shouldn't you add one to get the position in the string?
    Ben Van Johnson

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: find position of special characters in string

    RonanKeating,

    Posting an example workbook would go a long way to getting this resolved without needing a new iron mine to make more disk drives.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    08-30-2012
    Location
    Kansas City, Missouri
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: find position of special characters in string

    A little over three years late, but I just read the thread:


    Assuming Cell A1 = 15(Phi)12/15 L=315


    Please Login or Register  to view this content.
    to find the slash
    'Find Slash Position
    i = 1
    Do Until b$ = "/" Or i = Len(a$)
    b$ = Mid(a$, i, 1)
    End If
    i = i + 1
    Loop

    If i = Len(a$) Then
    MsgBox ("Special Character Not In String")
    End If

    SlashPos = i - 1 'returns actual position


    Justin
    BSCE, EIT

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1