Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Datenpunkt kürzen - einzeilige Lösung gesucht

NEWS

  • Neuer ioBroker-Blog online: Monatsrückblick März/April 2026
    BluefoxB
    Bluefox
    5
    1
    136

  • Verwendung von KI bitte immer deutlich kennzeichnen
    HomoranH
    Homoran
    8
    1
    170

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    18
    1
    871

Datenpunkt kürzen - einzeilige Lösung gesucht

Scheduled Pinned Locked Moved JavaScript
5 Posts 3 Posters 393 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WolfgangFB
    wrote on last edited by
    #1

    Um von einem Datenpunkt wie z.B. esphome.0.083AF28E23F0.Sensor.1024935111.state den Teil ohne ".state" zu erhalten habe ich momentan folgende Funktion:

    function RemoveLast(InStr){
        // RemoveLast("alias.0.Raum.Arbeit.Licht.0.state") ergibt "alias.0.Raum.arbeit.Licht.0"
        var InStrSplit = InStr.split("."); 
        InStrSplit.pop(); // letzes Element weg
        return(InStrSplit.join("."))
        }
    

    Bekommt man das als Einzeiler hin?

    paul53P 1 Reply Last reply
    0
    • W WolfgangFB

      Um von einem Datenpunkt wie z.B. esphome.0.083AF28E23F0.Sensor.1024935111.state den Teil ohne ".state" zu erhalten habe ich momentan folgende Funktion:

      function RemoveLast(InStr){
          // RemoveLast("alias.0.Raum.Arbeit.Licht.0.state") ergibt "alias.0.Raum.arbeit.Licht.0"
          var InStrSplit = InStr.split("."); 
          InStrSplit.pop(); // letzes Element weg
          return(InStrSplit.join("."))
          }
      

      Bekommt man das als Einzeiler hin?

      paul53P Offline
      paul53P Offline
      paul53
      wrote on last edited by paul53
      #2

      @wolfgangfb sagte: Bekommt man das als Einzeiler hin?

      return id.substring(0, id.lastIndexOf('.'));
      

      id = InStr

      Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
      Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

      W 1 Reply Last reply
      0
      • paul53P paul53

        @wolfgangfb sagte: Bekommt man das als Einzeiler hin?

        return id.substring(0, id.lastIndexOf('.'));
        

        id = InStr

        W Offline
        W Offline
        WolfgangFB
        wrote on last edited by
        #3

        @paul53
        Super, danke, LastIndexOf kannte ich noch nicht.

        Hast Du vielleicht auch für diese Funktion einen Einzeiler für mich? (In einer Zahl an der Stelle "Stelle" ein Bit setzen oder löschen)

        function SetBit(Zahl, Stelle, Wert){
            var Maske = 1 << (Stelle);
            Zahl = (Wert == 1) ? Zahl |= Maske: Zahl &= ~Maske;
            return(Zahl); 
            }
        
        
        paul53P haus-automatisierungH 2 Replies Last reply
        0
        • W WolfgangFB

          @paul53
          Super, danke, LastIndexOf kannte ich noch nicht.

          Hast Du vielleicht auch für diese Funktion einen Einzeiler für mich? (In einer Zahl an der Stelle "Stelle" ein Bit setzen oder löschen)

          function SetBit(Zahl, Stelle, Wert){
              var Maske = 1 << (Stelle);
              Zahl = (Wert == 1) ? Zahl |= Maske: Zahl &= ~Maske;
              return(Zahl); 
              }
          
          
          paul53P Offline
          paul53P Offline
          paul53
          wrote on last edited by
          #4

          @wolfgangfb sagte: für diese Funktion einen Einzeiler für mich?

          function SetBit(Zahl, Stelle, Wert){
              return Wert ? Zahl | 1 << Stelle : Zahl & ~(1 << Stelle);
          }
          

          Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
          Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

          1 Reply Last reply
          0
          • W WolfgangFB

            @paul53
            Super, danke, LastIndexOf kannte ich noch nicht.

            Hast Du vielleicht auch für diese Funktion einen Einzeiler für mich? (In einer Zahl an der Stelle "Stelle" ein Bit setzen oder löschen)

            function SetBit(Zahl, Stelle, Wert){
                var Maske = 1 << (Stelle);
                Zahl = (Wert == 1) ? Zahl |= Maske: Zahl &= ~Maske;
                return(Zahl); 
                }
            
            
            haus-automatisierungH Offline
            haus-automatisierungH Offline
            haus-automatisierung
            Developer Most Active
            wrote on last edited by
            #5

            @wolfgangfb sagte in Datenpunkt kürzen - einzeilige Lösung gesucht:

            Hast Du vielleicht auch für diese Funktion einen Einzeiler für mich?

            Wenn Du selbst besser werden möchtest, schau Dir mal https://www.codewars.com/ an. Finde ich ein ziemlich cooles Projekt um etwas dazu zu lernen.

            🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
            🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
            📚 Meine inoffizielle ioBroker Dokumentation

            1 Reply Last reply
            1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            Support us

            ioBroker
            Community Adapters
            Donate

            273

            Online

            32.8k

            Users

            82.7k

            Topics

            1.3m

            Posts
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
            ioBroker Community 2014-2025
            logo
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Home
            • Recent
            • Tags
            • Unread 0
            • Categories
            • Unreplied
            • Popular
            • GitHub
            • Docu
            • Hilfe