Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Adding space in a string in middle and end

(0) ShareShare
ReportReport
Posted on by 64

hi,

I have a requirement to show all the sites in one string. And there is a custom table which has a relation of 1: n sites . 

Eg. I have site1,site2,site3....site10.

A custom table "Sitelinkage" is having column linkageid L001 . This Linkage ID can be associated to N number of sites with custom value assigned to site assigned  in this case .

site2= 1 , site 4=5 ,site 6 = 9 ,site 7 =12.

The requirement is that a text file will be created as below.

Site1 Site2 Site3 Site4 Site5 Site6 Site7 Site8 Site9
0 1 0 5 0 9 12 0 0

The problem is that when I am keeping a Tab space in between sites and its values . The string just removes them and print as below

0105091200.

The site1...site 9 is printing properly.

I have taken the variable of str1260 siteValue. 

Thanks,

VK

  • Alex Panait Profile Picture
    170 on at
    RE: Adding space in a string in middle and end

    You could try to create an electronic report to meet this requirement.

  • Martin Dráb Profile Picture
    231,793 Most Valuable Professional on at
    RE: Adding space in a string in middle and end

    By the way, I would use code like this to create the file:

    // Put values to the container. Don't bother with a separator at this time.
    container sites;
    while select SiteValue from customTable
    {
    	sites  = customTable.SiteValue;
    }
    
    CommaTextStreamIo io = CommaTextStreamIo::constructForWrite();
    // Here we specify the delimiter to be used between values
    io.inFieldDelimiter('\t'); 
    // Write the whole container at once
    io.writeExp(sites); 
    // Create a file and offer it for download. This is useful debugging
    // even if you're going to do something else with the file in your real code.
    File::SendFileToUser(io.getStream(), 'file.txt');

  • Martin Dráb Profile Picture
    231,793 Most Valuable Professional on at
    RE: Adding space in a string in middle and end

    info() won't show tabs, therefore it's useless for this debugging. The debugger proves that your sctring contains the right data, which is no suprise at all.

    Now you hopefully agree that the string contains tabs, therefore your theory that something failed at this was wrong. You have tabs in the string, but you fail to write the to the file, therefore writing to the file is the thing that you need to focus on.

  • vicky1234 Profile Picture
    64 on at
    RE: Adding space in a string in middle and end

    Hi Komi,

    Really appreciate your help and executing the job and sharing the results.

    I think my statements were not that clear but below screens will help more on the issue.

    pastedimage1665160648478v1.png

    The first ones i.e  lets say site1 ...site 10 will be header for the third party and the records after that will be the actual values...
    so in the above case consider 10 20 ...150 as the site header separated by space/tab and this is working fine,

    Now when I am sending the data for the next line it will be having data starting from 10 then 20 and so on till 150 .

    so in my case lets say value of site 30 is one and for 140 - > two.

    now these values are also properly assigned during the debug I can see as below there are spaces in between.

    pastedimage1665160887378v2.png

    The problem is that when you see this values in the output window it will just trim the empty spaces in between as shown below.

    pastedimage1665160966118v3.png

    This will be wrong as this data will go into a csv...
    This has to be sent in a single column only as there are some complex requirements.

    Not sure if this is std way that is shows but this is the issue which i am facing.

  • Komi Siabi Profile Picture
    12,772 Most Valuable Professional on at
    RE: Adding space in a string in middle and end

    Hello Vicky,

    I tried your code. See below:

    As you can see, I used 

    tab , " " , x.

    public static void main(Args _args)
    {
        LoanRequestTable customTable;
        #define.Tab('\t');
    
    
        str1260 siteStrtab, siteStrspace,siteStrx; //variable declared
    
        while select LoanEDs from customTable
        {
            siteStrtab  = customTable.LoanEDs   #Tab;
            siteStrspace  = customTable.LoanEDs  "   ";
            siteStrx  = customTable.LoanEDs   "x";
        }
    
        Info(strFmt("%1",siteStrtab));
        Info(strFmt("%1",siteStrspace));
        Info(strFmt("%1",siteStrx));
    }

    tab.png

  • vicky1234 Profile Picture
    64 on at
    RE: Adding space in a string in middle and end

    Hi Girish,

    I have written the same code and printing it via info(strfmt()), not sure why do we need the con2str method.

    If you run this same job and see the info then it will remove the spaces in between. You can consider any std table to check

  • GirishS Profile Picture
    27,823 Moderator on at
    RE: Adding space in a string in middle and end

    Try to insert the values into container with space.

    While printing use con2str function for conversion.

    str1260 siteStr;//variable declared
    container site;
    while select from customtable
    
    {
    
    site  = customtable.sitevalue   " ";
    
    }
    

    Thanks,

    Girish S.

  • vicky1234 Profile Picture
    64 on at
    RE: Adding space in a string in middle and end

    Thanks Martin,

    I will use the code editor.

    I need to add space in between the sitevalues and this values will sit in 1 single column , which is why I am considering str1260.

    The issues is that it if I try to give any spaces in between it just skips and in case of any other values let's say " -" then it prints correctly.

    So the problem is to fix the section where empty space in the string is skipped.

  • vicky1234 Profile Picture
    64 on at
    RE: Adding space in a string in middle and end

    Hi Komi

    Thanks for the comment.

    I have created a macro and [tag:Tab] value is '\t' but it still prints the output without the spaces.

  • Martin Dráb Profile Picture
    231,793 Most Valuable Professional on at
    RE: Adding space in a string in middle and end

    vicky1234, please don't forget using Insert > Code to paste source code. Let me re-post your code in the right way. I also fix a bug there and corrected letter casing:

    str1260 siteStr; //variable declared
    
    while select SiteValue from customTable
    {
    	siteStr  = customTable.SiteValue   #Tab;
    }

    Unfortuntately this code doesn't look relevant to your problem. Your problem is about writing this string to a file.

    Also, it's not clear why you add the delimiters by yourself. The usual approach is using a column delimiter when writing to a file.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,927 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,793 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans