Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Get all the values bef...
Finance forum

Get all the values before and after a character in string

Posted on by 99
I have a requirement where i have two customers A n B, and a string STR1 = 'Abcd-345/123-def', the requirement says -
for customer A: str 1 should have all the values before the character /
i.e. for customer A : str1 =Abcd-345
for customer b: str 1 should have all the values after the character /
i.e. for customer B : str1 =123-def
 
How do i achieve this using str function in d365 fo and x++, can anyone help me with this?
  • Martin Dráb Profile Picture
    Martin Dráb 227,979 Super User 2024 Season 2 on at
    Get all the values before and after a character in string
    Yes, I mentioned both strScan() and subStr() in my last reply. The usage can be seen in the standard methods I suggested before.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,532 Moderator on at
    Get all the values before and after a character in string
    We have a function called substr() which cuts the string based on the size and position of the character till where it should be removed. Also we have strscan() function which finds the particular character and returns the position. Using these 2, first find the position of the character you are looking for and then simple use that in substr which solves your requirement.
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,979 Super User 2024 Season 2 on at
    Get all the values before and after a character in string
    "I don't want" is a not a good explanation of the problem you have with it. How I can give you a solution that doesn't have the same problem if you tell me what the problem is? Or maybe you don't have a good reason and what needs to change is your approach.
     
    I already suggested another solution if you don't like strSplit(): str2con().
     
    And of course, if you have too much time, you can develop and test your own solution doing the same thing, such as with strFind() or strScan() and subStr(). See the code of strSplit() and/or str2con() to see how Microsoft did that.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,979 Super User 2024 Season 2 on at
    Get all the values before and after a character in string
    You can use functions like strSplit() or str2con() to split the string to components. Then you'll take the one you want in the particular case.

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,142 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,979 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans