Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] Zeichen in String einfügen

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [gelöst] Zeichen in String einfügen

    This topic has been deleted. Only users with topic management privileges can see it.
    • paul53
      paul53 @Delamaris last edited by

      @delamaris
      Ist das Javascript?

      1 Reply Last reply Reply Quote 0
      • D
        Delamaris last edited by

        ah habe ich vergessen 🙂 ist nicht geheim

        3:22:28.173 error javascript.0 (1689479) script.js.111111 compile failed: at script.js.111111:3
        Cannot find name 'StringBuffer'.(2304)

        1 Reply Last reply Reply Quote 0
        • D
          Delamaris last edited by

          @paul53
          ich weiss nicht ob das wirklich Javascript ist.

          habe ich hier gefunden:
          https://www.delftstack.com/de/howto/java/add-char-to-string-java/

          bahnuhr paul53 2 Replies Last reply Reply Quote 0
          • bahnuhr
            bahnuhr Forum Testing Most Active @Delamaris last edited by

            @delamaris

            zeig doch mal den string den du hast.
            Ist der immer gleich, oder ändert der sich.

            Und dann genau beschreiben was wohin soll.

            1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @Delamaris last edited by

              @delamaris sagte: habe ich hier gefunden:

              Javascript ist nicht Java!

              1 Reply Last reply Reply Quote 0
              • D
                Delamaris last edited by

                @bahnuhr

                Der String ist von Sonos Adapter current_title.
                Der sieht momentan so aus "Taylor Swift - Blank Space" und änder sich natürlich.
                Mein Display hat in 1 Linie aber nur 17 Zeichen sichtbar.
                Also müsste nach dem 17 Zeichen das "[l4c1]" eigefügt werden damit der Rest vom String in eine neue Zeile kommt.

                bahnuhr paul53 2 Replies Last reply Reply Quote 0
                • bahnuhr
                  bahnuhr Forum Testing Most Active @Delamaris last edited by

                  @delamaris

                  Lösung:

                  var dp = "Taylor Swift - Blank Space";
                  var neu_dp = dp.substring(0,17) + "[l4c1]" + dp.substring(17,dp.length);
                  log (neu_dp);
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @Delamaris last edited by paul53

                    @delamaris sagte: nach dem 17 Zeichen das "[l4c1]" eigefügt werden

                    Javascript für ioBroker:

                    // IDs anpassen!
                    const idSonos = 'sonos.0.abc';
                    const idDisp  = 'xyz';
                    
                    on(idSonos, function(dp) {
                        let str = dp.state.val;
                        if(str.length > 17) str = str.substring(0, 17) + '[l4c1]' + str.substring(17);
                        setState(idDisp, str);
                    });
                    

                    EDIT: Es sieht sicherlich besser aus, wenn man das letzte Leerzeichen in den ersten 17 Zeichen durch die Zeilenschaltung ersetzt.

                        if(str.length > 17) {
                            let space = str.lastIndexOf(' ', 17);
                            if(space > 10) str = str.substring(0, space) + '[l4c1]' + str.substring(space + 1);
                            else str = str.substring(0, 17) + '[l4c1]' + str.substring(17);
                        }
                    
                    1 Reply Last reply Reply Quote 0
                    • D
                      Delamaris last edited by Delamaris

                      Boah, es funktioniert.

                      Vielen vielen Dank an alle Beteiligten.

                      paul53 1 Reply Last reply Reply Quote 0
                      • paul53
                        paul53 @Delamaris last edited by

                        @delamaris sagte: es funktioniert.

                        Dann setze bitte das Thema in der Überschrift des ersten Beitrags auf [gelöst].

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        775
                        Online

                        31.6k
                        Users

                        79.6k
                        Topics

                        1.3m
                        Posts

                        5
                        13
                        769
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo