1. The forum will be closing soon permanently. Please read the announcement here

    Note: User registration has been closed. We do not accept any new accounts.

CustomData adds extra space to each line.

Discussion in 'Programming (In-game)' started by Ronin1973, May 21, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Ronin1973

    Ronin1973 Master Engineer

    Messages:
    4,964
    Whenever I copy and paste lines of text into the custom data field or manipulate the .CustomData string via code, there's always an extra empty space at the end of each line before the carriage return/new line, Environment.NewLine, etc.

    I'm working with "MMaster's Automatic LCDs 2" and in order to manipulate the what's displayed on an LCD screen I have to access the custom data for that LCD.

    Is there any way possible to get rid of that extra space (" ") attached to the end of each line?
    Maybe block.CustomData.Replace(" \n", "\n"); ?

    Things that are manually typed in don't have this problem. Things that are copied or manipulated with the programmable block do.
     
  2. Inflex

    Inflex Developer Staff

    Messages:
    397
    The thing you see as the "whitespace" inside SE custom data editor is most probably a '\r' character.

    Default "New-liner" in Windows is "\r\n" sequence but since SE are using only '\n' character to make a new line the '\r' is unrecognized and left in SE editor as a visible whitespace.

    Switch your windows text editor into Unix like mode (aka '\n') and everything should be fine
     
    • Like Like x 1
    • Informative Informative x 1
  3. Ronin1973

    Ronin1973 Master Engineer

    Messages:
    4,964
    Thanks for the advice. I'll take another stab at it. Though, this also happens when pasting data from one block's Custom Data field to another's WITHIN the game.
     
  4. Inflex

    Inflex Developer Staff

    Messages:
    397
    There is nothing like "within the game". It always goes across the system clipboard and Windows will normalize it to it's own format ;)
     
  5. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    if its manipulated programmatically by a script it bypasses the clipboard.
    @Ronin1973 can you provide us with an example of how you are building the string, as well as the line you have to write to custom data? I've done exactly what you are trying to do (here https://forums.keenswh.com/threads/display-driver-demo-stand.7394025/)
    have a look at the script in there for writing to the display's customdata field. it does work, and there is no extra space included, which makes me think there is a mistake in either the way you are building the string, or the way you are writing it to customdata
     
  6. Ronin1973

    Ronin1973 Master Engineer

    Messages:
    4,964
    Thank you everyone. I got it sorted. I followed @Inflex 's instructions and simply used a \n at the end of the line and nothing else. Did the job.

    One more step closer to my big missile cruiser with menu driven missiles/accessories.
     
    • Informative Informative x 1
  7. Wicorel

    Wicorel Senior Engineer

    Messages:
    1,263
    I had reported this long ago. It effects ALL text fields like program text, etc.

    STR:
    1. type text in a blank text box (text panel, for example). Type multiple lines. Ensure that there are no extra spaces at the end of the lines
    2. select all the text (CTRL+A).
    3. Copy the text (CTRL+C).
    4. Paste the text (CTRL+V).
    5. Note that there are now spaces at the end of each line.
     
  8. Martin R Wolfe

    Martin R Wolfe Trainee Engineer

    Messages:
    83
    You could when parsing the code from CustomData after splitting on the '\n' just strip the leading and trailing whitespace before doing anything else with the string.

    Here is an example from one of my scripts:-
    Code:
                case "ExternalPressureSensor":
                    aParameter.Values.ForEach(SensorName=>{
                        if(String.IsNullOrWhiteSpace(SensorName))
                            throw new Exception("Sensor name error. Name is empty string!");
                        if(!saExternalPressureSensors.Exists(x=>(x==SensorName.Trim())))
                            saExternalPressureSensors.Add(SensorName.Trim());
                        else throw new Exception("Sensor name warning.\nDuplicate name - "+SensorName.Trim());});
                    break;
    
     
Thread Status:
This last post in this thread was made more than 31 days old.