how to split file name

Home Page Forums BizTalk 2004 – BizTalk 2010 how to split file name

Viewing 2 reply threads
  • Author
    Posts
    • #22121

      Hi I have a scenerio where I need to extract some part of data from the inbound filename like my file name would be  

      robert_telecom_wired_02102009

      from the above filename I need to extract ‘telecom’ and assign it to a variable so that I can use it in decide shape and do my processing. How can I achieve this in the expression shape? 

       

      Thanks in Advance

    • #22123

      You can do that using C# Split Function.

      For Ex:

       

      har[] delimiterChars = { ' -'};
      String yrString  = "robert_telecom_wired_02102009";
      String[] parsedStrings = yrString.Split(delimiterChars);
      Now u can look for your string
      
      
      
      
      parsedStrings.values(); Depending on u r Requirement.
      
      

       

    • #22126

      You will need to create a new Class Library project in your BizTalk solution and add a single public static class that is marked as Serializable. Within that class, create single public static method called ExtractFilename (or any other name you feel is suitable) passing in the filename you received. The method should return a string.

      Using either a string split, or substring methods extract the part of the filename you are looking for and return that from the method. You may also want to ‘ToUpper()’ the result before you return it from the method so your Decide shape only needs to check one case.

      Add a reference to the project created above in your BizTalk project (that contains the orchestration that needs to consume this method) and in your orchestration Decide shape, reference the method in the left handside of your compaison, e.g.:

      StaticClass.ExtractFilename(InputFilename) == “TELECOM”

      If you need to put the value into a variable, simply assign it as follows and use the variable in your Decide shape comparison.

      variable = StaticClass.ExtractFilename(InputFilename);

      This approach is also testable using your favourite testing framework, in that the static ExtractFilename method can be tested in isolation from the orchestration expression. I use a similar approach, using RegEx’s to check that the method returns the expected string format.

      Hope this helps, Nick.

      • #22131

        Hi Thanks for your reply’s I have a question Cant I do like this

        FileName = “robert_telecom_wired_02102009”;

        FileExtract = FileName.Substring(8,14);

        wont I get “telecom” from the file name. I havent test this procedure I am just asking you does it work.

         

        Thanks

      • #22137

        Hi Thanks for your reply’s I have a question Cant I do like this

        FileName = “robert_telecom_wired_02102009”;

        FileExtract = FileName.Substring(8,14);

        wont I get “telecom” from the file name. I havent test this procedure I am just asking you does it work.

         

        Thanks

      • #22139

        Hi Nick Thanks for teh reply, how will the C# code look like do you have any code examples for the split function like how to write the code to split.

        Thanks

Viewing 2 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.