Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Integration Manager - Replace

Posted on by 205

I'm importing customers and need to build the Customer ID field.  However, I need to clean up the string before I do, leaving only alphabetic characters.  I'm on the struggle bus with the replace function and can't figure it out.  Note:  If I use " " instead of "[^a-zA-Z]", it'll replace spaces properly so...  Here's what I've got, with msgbox in there for troubleshooting.

Dim ID_str
Dim s

s = SourceFields("Customer_Name")
s = Replace(s,"[^a-zA-Z]", "")
msgbox(s)
ID_str = left(s,5)
ID_str = UCase(ID_str & SourceFields("Customer_ID") & "EM")
CurrentField = ID_str


*This post is locked for comments

  • SaintFrag Profile Picture
    SaintFrag 205 on at
    RE: Integration Manager - Replace

    I knew how to clean it in SQL, but the question was how to do it in VB in Integration Manager.

  • Suggested answer
    L Vail Profile Picture
    L Vail 65,271 on at
    RE: Integration Manager - Replace

    SaintFrag,

    First I'd like to say that this isn't a script I created, but I didn't record from whom I got it. Thank you whomever you are:

    CREATE FUNCTION dbo.CleanString

    /*******************************************************************************

    Purpose:

    Given a string and a pattern of characters to remove, remove the patterned

    characters from the string.

    Usage:

    --===== Basic Syntax Example

    SELECT CleanedString = dbo.CleanString(@pSomeString,@pPattern)

    ;

    --===== Remove all but Alpha characters

    SELECT CleanedString = dbo.CleanString(st.SomeString,'%[^A-Za-z]%');

      FROM dbo.SomeTable st

    ;

    --===== Remove all but Numeric digits

    SELECT CleanedString = dbo.CleanString(st.SomeString,'%[^0-9]%');

      FROM dbo.SomeTable st

    ;

    Programmer Notes:

    1. @pPattern is case sensitive.

    2. The pattern set of characters must be for just one character.

    Revision History:

    Rev 00 - Circa 2007 - Author Unknown

           - Initial find on the web

    Rev 01 - 29 Mar 2007 - Jeff Moden

           - Optimize to remove one instance of PATINDEX from the loop.

           - Add code to use the pattern as a parameter.

    Rev 02 - 26 May 2013 - Jeff Moden

           - Add case sensitivity

    *******************************************************************************/

           (@pString VARCHAR(8000),@pPattern VARCHAR(100))

    RETURNS VARCHAR(8000) AS

     BEGIN

           DECLARE @Pos SMALLINT;

            SELECT @Pos = PATINDEX(@pPattern,@pString COLLATE Latin1_General_BIN);

             WHILE @Pos > 0

            SELECT @pString = STUFF(@pString,@Pos,1,''),

                   @Pos = PATINDEX(@pPattern,@pString COLLATE Latin1_General_BIN);

    RETURN @pString;

       END

    ;

    GO

    Kind regards,

    Leslie

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans