text:
Print last inputted byte
Challenge
You have one string of input bytes, output only the last byte in it.
Rules
Your submission may be a program or function outputting the last byte in the input which

is either a string, stdin or command-line arguments, and
is non-empty.

I was trying to solve this with brainfuck, however all languages are allowed to participate. This is code-golf.
Examples
"?" -> "?"
"29845812674" -> "4"

Welcome, I changed your question to fit our format more properly (note this is what the sandbox is for, usually). However in its current state the challenge is very easy (also in bf), so not sure about that.

I vote against closing; it may be trivial, but that doesn't make it offtopic

@MillyWay I think most of the close votes were before the extensive edit by ბიმო

@ბიმო We have a consensus not to edit off-topic questions to make them on-topic which I think would have applied here.

What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?

@FireCubez Yes, ASCII only

@jean Does every string you are to input to the program have only printable ascii (32 to 126), or do some of they have nonprintables and control characters?

x86-16 machine code, 2 bytes
As @CodyGray correctly points out, taking input as a string and output to a register removes the bulk of the standalone program version.
Input string is in SI, length in CX and output character is in AL:
F3 AC  REPZ LODSB      ; start at memory location pointer in SI, put next value in AL,
                       ; loop CX number of times. The last char will be in AL when done.

Or 4 bytes as a "Pascal string" (length is prepended to beginning of string):
AC     LODSB           ; first byte is string length
91     XCHG AX, CX     ; move length to CX for loop
F3 AC  REPZ LODSB      ; start at memory location pointer in SI, put next value in AL,
                       ; loop CX number of times. The last char will be in AL when done.

Or 5 bytes as a "C string" (zero/null terminated), input in DI:
F2 AE     REPNZ SCASB     ; scan for value in AL (0), end when found and advance DI
8A 45 FE  MOV AL, [DI-2]  ; DI is now two bytes ahead of last, put value of DI-2 into AL

x86-16 machine code, IBM PC DOS, 12 11 10 bytes
Or as complete program as IBM PC DOS executable.  Input is from command line, output is to console.
B3 80   MOV  BL, 80H            ; BX to DOS PSP at 80H
8A 07   MOV  AL, BYTE PTR[BX]   ; get command line tail length
D7      XLAT                    ; AL = [BX+AL]
B4 0E   MOV  AH, 0EH            ; PC BIOS write to screen function
CD 10   INT  10H                ; display
C3      RET                     ; exit to DOS

Output:

Although this certainly gets style points, from a strict golfing point of view, it's worth noting that you are allowed to write functions that return the result in a register. So, this can get a lot shorter. You can trivially eliminate 4 bytes, and a rewrite could shrink it down even further. By the way, is that screenshot from an emulator? Which one?

@CodyGray, oh absolutely, the code to take input from command line and output to console is nearly all of it.  Yeah, I could say "input string in SI, length in CX output char is in AL" and then I think the only code that would be necessary is REPZ LODSB (2 bytes) and we'd be done. Of course this approach wouldn't be how you do it if you were coding for efficiency, not size. Your point is very well taken though, I'll post it also as a function that does the meat of the work.

Attache, 4 bytes
Last

Try it online! (If the input could be a list of characters, &/S could work.)
Alternatives
5 bytes: `@&-1
8 bytes: &/S@List
10 bytes: `@«_,-1»
10 bytes: Fold!Right
10 bytes: `@<~_,-1~>
10 bytes: `^^&:Right
10 bytes: {Right^^_}
11 bytes: Get«_,-1»
11 bytes: Get<~_,-1~>
12 bytes: `@«_,#_-1»
12 bytes: `@<~_,#_-1~>
13 bytes: Get«_,#_-1»
13 bytes: Get<~_,#_-1~>

:| wtf so many alternatives

@ASCII-only Least I could do on a simple challenge like this :p

Print Last inputted byte. The programs contents fit with the challenge

Brainf***, 7 bytes
,[>,]<.

https://ideone.com/XoJLD0
It still doesn't work ;(

@jean Try it here. (Honestly, I didn't even know ideone did BF).

Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(

@jean ideone seems to use -1 as the EOF. +[>,+]<-. should work

@Jo King Sorry, but the input looks like: 29845812674[enter][EOF]
how can I print the last digit?

@jean You have to make a new question for that challenge

@jean do <<-. instead of <-.?

@Jo King Yes!!! +[>,+]<<-. That's it!!! Thanks a lot!!!

MATL, 2 bytes
0)

MATL uses 1-based modular indexing so this solution grabs the element in the 0-th position of the input which is the same as the last since the 0 wraps around to the end.
Try it out at MATL Online
Explanation
    % Implicitly grab the input
0   % Push the literal 0 to the stack
)   % Use this zero to grab the character at the end of the string
    % Implicitly display the result

I'd have gone for J)...

INTERCAL, 270 258 247 246 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$.1~#256DO.2<-.3DO(1)NEXTPLEASE.2<-!3~#15'$.3~#240PLEASE.2<-!2~#15'$.2~#240PLEASE.2<-!2~#15'$.2~#240DO(1010)NEXTDO,1SUB#1<-.3DOREADOUT,1(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1

Try it online!
-8 thanks to 鳴神裁四点一号 removing DOGIVEUP to terminate by NEXT stack explosion, opening up another -4 changing a PLEASE to DO.
-11 removing some grouping from the bit-reversing expression from hell. It seems that binary operators generally act right-associative in C-INTERCAL, though having no precedence among themselves.
-1 trying something else for bit reversal--definitely expected more savings than that! A more principled approach might be able to do it in two steps unless there's some obvious invariant I'm missing, but I'm too tired to take a stab at that just yet.
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
        DO ,1<-#1             PLEASE NOTE We want the input array to only have space for one element, so it will only take one at a time
        DO COME FROM (2)
        DO WRITE IN ,1        PLEASE NOTE If this is the first byte of the input, it'll write its value... but if not, it'll write the
                              previous value minus its value mod 256.
        DO .1<-,1SUB#1
        DO .5<-#1$!1~#256'    PLEASE NOTE .5 is 3 if the input is 256, 2 otherwise
        DO .2<-.3
        DO (1) NEXT

                              PLEASE NOTE If we're here, we've found the end of the input. Now, we need to print it back out... C-INTERCAL's
                              array I/O, in order to determine what it will actually print, subtracts the value it's going to print from the
                              previous one (still mod 256, and with the previous value defaulting to 0), and then reads the bits of the byte
                              backwards. So in order to go from the value we want to display to the value we need to feed into READ OUT, we
                              reverse the bits and then subtract from 256. Rather than select the bits out individually and mingle them all
                              in one expression, I mingle the back and front halves of the byte until it adds up to a reversal.

        DO .2 <- !3~#15' $ !3~#240'
        DO .2 <- !2~#15' $ !2~#240'
        DO .2 <- !2~#15' $ !2~#240'

        DO (1010) NEXT        PLEASE NOTE .1 already has 256 in it, which is very convenient for when you need to subtract .2 from 256.

        DO ,1SUB#1 <- .3      PLEASE NOTE If we just read .3 out, we'd get a Roman numeral instead of the correct output.
        DO READ OUT ,1

        DON'T GIVE UP         PLEASE NOTE Logical end of program. However, if we don't gracefully terminate here, nothing more is output,
                              and the FORGET can't keep up with the NEXTs.

    (1) DO (1002) NEXT        PLEASE NOTE that that line in syslib does 1001 next, which pops .5 entries off the next-stack and returns
                              control flow to the last one, such that if .5 is 2 flow will come back here, but if it's 3 then it'll go back
                              to the line that nexted to this one.

                              Here we add .1 and .2 into .3, then truncate it to a byte before looping back (while managing the next-stack
                              responsibly so the program doesn't disappear into the black lagoon for any input over 79 (?) bytes)

        DO (1009) NEXT
        DO .3<-.3~#255
    (2) DO FORGET #1

DOGIVEUP can be removed to golf off 8 bytes because program halts by stack overflow and output is unchanged

PHP, 13 bytes
<?=$argn[-1];

Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php

Python 3, 14 bytes
lambda x:x[-1]

Try it online!

I feel dumb, how are you calling this without declaring it to a variable?

I looked at your TIO, but it doesn’t make much sense... What are you doing in your header?

@Bobawob For your first question, anonymous lambdas are allowed for answers (I call it using by assigning the lambda to the variable e in the header). For your second question, the header is e=\ , which basically means e=lambda x:x[-1]

Note that in my above comment, there is not supposed to be a trailing space in e=\  but Markdown escapes the code character so I have to add a trailing space

That’s really cool! Thank you!

@NathanDimmer Thanks! When you make an anonymous lambda as a PPCG answer, you should use the format my answer used for the TIO link to make it easier to test your test cases

Javascript, 14 bytes
a=>a.slice(-1)

I tried my best to find a shorter way but to my surprise I don't think this can be improved, unless there is a funky way to reverse a string in under 8 bytes, before calling [0]. Or maybe if there is a short way to get array length. Different approach: a=>[...a].pop() (15bytes)

@Matsyir a=>/.$/.exec(a) also 15

Haskell, 9 4 bytes
last

Try it online!

Why bother with pure? Isn't last enough?

I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".

TI-BASIC (TI-84), 10 bytes
sub(Ans,length(Ans),1

Gets the last character in the input string.
Input is in Ans.
Output is in Ans and is automatically printed out.

Bash + coreutils, 8 bytes
tail -c1

Input is from stdin, output is to stdout.

Turing Machine But Way Worse, 391 bytes
1 0 1 1 0 0 0
0 0 0 1 1 0 0
1 1 1 1 0 0 0
0 1 0 1 2 0 0
1 2 1 1 0 0 0
0 2 0 1 3 0 0
1 3 1 1 0 0 0
0 3 0 1 4 0 0
1 4 1 1 0 0 0
0 4 0 1 5 0 0
1 5 1 1 0 0 0
0 5 0 1 6 0 0
1 6 1 1 0 0 0
0 6 0 1 7 0 0
1 7 1 1 0 0 0
0 7 0 1 8 0 0
1 8 1 1 0 0 0
0 8 0 0 9 0 0
0 9 0 0 a 0 0
0 a 0 0 b 0 0
0 b 0 0 c 0 0
0 c 0 0 d 0 0
0 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 0 0 h 0 0
0 h 0 0 g 0 0
0 g 0 0 0 1 1
1 g 1 0 0 1 1

Try it online!
EXPLANATION
Detect eight zero bits (which will occur at the end of the input, since TMBWW uses an infinite tape of bits.)
1 1 1 1 0 0 0
0 1 0 1 2 0 0
1 2 1 1 0 0 0
0 2 0 1 3 0 0
1 3 1 1 0 0 0
0 3 0 1 4 0 0
1 4 1 1 0 0 0
0 4 0 1 5 0 0
1 5 1 1 0 0 0
0 5 0 1 6 0 0
1 6 1 1 0 0 0
0 6 0 1 7 0 0
1 7 1 1 0 0 0
0 7 0 1 8 0 0
1 8 1 1 0 0 0
0 8 0 0 9 0 0

-------------

When eight 0 bits are detected, move back to the final byte of the input and print it out while halting the program.
0 9 0 0 a 0 0
0 a 0 0 b 0 0
0 b 0 0 c 0 0
0 c 0 0 d 0 0
0 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 0 0 h 0 0
0 h 0 0 g 0 0
0 g 0 0 0 1 1
1 g 1 0 0 1 1

Excel, 10 bytes
Pretty much equivalent to @remoel's VBA answer:
=RIGHT(A1)

Seed, 11 bytes
5 370394306

Try it online!
The resulting Befunge-98 program ~2j@, was stolen borrowed from Jo King here, so credit to them for that.

Java 11+
Input from STDIN, 71 61 bytes
-10 bytes thanks to OlivierGrégoire
v->{var x=System.in;x.skip(x.available()-1);return x.read();}

Try it online!

Function Argument, 25 bytes
s->s.charAt(s.length()-1)

You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwise s->s[s.length-1] would have been enough with a char[] parameter-type.

61 bytes.

@OlivierGrégoire just now seeing your answer 2 years later. Thanks.

Mornington Crescent, 389 Bytes
Even a task as simple as this presents an interesting optimisation challenge when riding the London Underground.
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take Central Line to Holborn
Take Piccadilly Line to Heathrow Terminals 1, 2, 3
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Parsons Green
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Try it online!
Visiting Mile End station allows you to take a substring from the end of the input - but to chop just 1 character, you need to generate the integer 1 somehow. Rather than doing any arithmetic, the fastest method turns out to be to parse it from the station name "Heathrow Terminals 1, 2, 3".
To bypass that, an alternate strategy for this challenge would be to reverse the input, read the character code for the now first byte, and then turn that back into a char to output - but this approach takes 12 bytes longer. (Although there are fewer trips needed, so the tickets would be cheaper.)

Arn, 2 bytes
:}

Pretty simple, the suffix :} gets the last element of an array (implicit casting)

Another alternative: _\

+1 for a happy symbol

Befunge-93, 12 15 bytes
:1+_p1-,@>~#

Try it online!
Thanks to @Jo King for golfing off 3 bytes.
Alternate 15 byte version that is less messy:
~:1+#v!_
  @,$<

Taking strings as input in Befunge isn't the easiest.  If there were a single command to take in multiple characters, it would be as simple as reading the string, popping/printing the top character, and exiting.

Actually, $$ instead of p1 should work without the warning for the same amount of bytes

Jelly, 1 byte
Ṫ

Try it online!
Not the most difficult challenge in Jelly...
Note this accepts the input as a string; if the input could be interpreted otherwise (e.g. a number, a list), then it the argument will need to be quoted (e.g. "123456" or "[123,197]"). Alternatively this can be seen as a link that takes a byte array and returns the last member of that array, in accordance with PPCG standard rules.
Thanks to @MilkyWay90 and @ბიმო for pointing this out.

-1 Fails for any number (https://tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)

@MilkyWay90: Doesn't need to be a full program, probably this will work as a Jelly function taking a string. But then again I don't know Jelly, so I might be wrong.

Okay, I'll try seeing whether or not it will work as a link

@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)

You can just define the T as a link and make it input a string, removing the need for "" in your input.

><>, 2 bytes
Using command line args
o;

Try it online!
><>, 11 bytes
Using stdin
\~o;
/?(0:i

Try it online!

05AB1E, 1 byte
¤

Try it online!
θ or ` would also work.

Cubix, 6 bytes
pA/@po

Try it online!
  p
A / @ p
  o

Watch it run

A Takes all the input
/ Redirect around the cube
pp bring bottom of the stack to the top twice
o/@ output as character, redirect and halt

Emotion, 5 bytes

Explanation
 Push a copy of the first stack value.
 Push the length of the first stack value interpreted as a string.
 Push literal 1
 Push the difference of the second and first stack values.
 Push the character of the second stack value at the index of the top stack value.

Try it online!

in your readme, 1. i think "to emoji" should be "from emoji" 2. if it should be "from emoji" then emotinomicon and emojicode are a thing already

Actually what you're looking at is output from a compiler, which can also be accessed via the online interface.

Isn't each emoji more than one byte? I'd think they'd be two bytes at least.

Emotion uses a custom code page. See https://quantum64.github.io/EmotionBuilds/1.1.0//?state=JTdCJTIybW9kZSUyMiUzQSUyMmNvZGVwYWdlJTIyJTdE

Cascade, 9 bytes
?a|,
;.]^

Pretty happy with this, as it is only 3 bytes longer than my cat program
Expanded
   ?
  ^;.
 | |a
 ] |
a ,|

This essentially just loops through pushing input characters into the a stack until EOF is reached. Then it outputs the item at the top of the a stack using .a.
Try it online!

Rust, 25 16 10 bytes
|s|s.pop()

Try it on the Rust Playground!
An anonymous function that takes in a mutable String and outputs the char at the end of the string. Minus a lot of bytes, thanks to madlaina

The .unwrap() call isn't necessary as per this meta post. Also, if you use the closure in a function that requires a specific signature, the compiler can do a better job at type deduction and you can leave the :String out: example

@madlaina thanks, I was testing with let bindings, and I had to be explicit there.

PowerShell, 11 bytes
"$args"[-1]

Try it online!

SmileBASIC, 16 bytes
INPUT S$?POP(S$)

Bash, 13 bytes
echo ${1: -1}

string is passed as argument.
Try it online !

Python 3, 11 18 34 Bytes
import sys;print(sys.argv[-1][-1])

Usage via running the program as a python script on the command line. Input is provided as the last argument to the program.
Try it online!

This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.

Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.

38

14

How about this?

that should work too

The first -1 can just be 1, or alternatively, the lambda is valid

Turing Machine Code, 72 42 bytes
Assumes an input with no empty cells (spaces). Thanks to ASCII-only for saving 30 bytes.
0 * * r 1
1 * * l 2
1 _ _ l halt
2 * _ r 0

Old version in 72 bytes:
0 * * r 0
0 _ * l 1
1 * * l 2
2 * _ l 2
2 _ _ r 3
3 _ _ r 3
3 * * * halt

Try it online.

0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?

oi pls reply :||

wouldn't work in what way? I've tested it online

@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.

Well, this is a simple challenge, don't think it needs more than one answer in any language :P

@ASCII-only Okay then.

Twig, 37 bytes
This just uses a simple "extract 1 char from the end and print it" aproach.
{%macro a(a)%}{{a[-1:1]}}{%endmacro%}

It was really easy to do, and test, but was fun!

To use it, you have to put it on a .twig file and import it:
{% import 'a.twig' as a %}
{{ a.a("string") }} {# should display "g" #}

You can test it on https://twigfiddle.com/aa19wd (testcases included)

Ok, that's the first time I see a Twig golf.

@Ven I've been doing it for quite a while. Here's an example: https://codegolf.stackexchange.com/a/174040/ and here's another one: https://codegolf.stackexchange.com/a/166800/ (I have a few more, but well)

APL+WIN, 4 bytes
¯1↑⎕

Prompt for input string and select last byte.

3 byte solution ⊃⌽⍞

VBA (Excel), 14 12 bytes
using Immediate Window and Cell A1 as input
Thanks @tsh
?[RIGHT(A1)] or ?Right([A1],1)

Is 1 optional?

not on the second code. Thanks :)

IBM/Lotus Notes Formula, 11 bytes
@Right(i;1)

Computed field formula taking its input from editable field i

C# 8.0, 8 bytes
Requires .NET Core 3.0, which is in beta. This currently crashes the CLR due to a bug, but once the bug is fixed, this will run as expected and fulfill the challenge requirements.
s=>s[^1]
C# 8.0, Runs without crashing at time of writing, 22 bytes
s=>s.ToCharArray()[^1]
C# 8.0, Full Program, 78 bytes
using C=System.Console;class A{static void Main(){C.Write(C.ReadLine()[^1]);}}

The challenge mentions "output", so the last solution is probably the right one

Dang, you outdid my console answer by a lot.  How does the ^1 work?

It's the new Index type. Starting an index with a caret indicates it's from the end, i.e. array[^n] is the same as array[array.Length - n]

Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?

Found it: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0

LiveScript, 8 bytes
(.[*-1])

Explanation:
(.[*-1])
(.[*-1]) # "BIOP": operator section à la Haskell
 .[   ]  # Index into the implicit argument
   *-1   # In [], "*" refers to the length

Forth (gforth), 17 bytes
: f 1- + 1 type ;

Try it online!
Explanation
Adds string-length - 1 to the string address and then prints a string of length 1 starting at that address.
Code Explanation
: f        \ start a new word definition
  1-       \ subtract 1 from string length
  +        \ add result to string address
  1 type   \ print string of length 1 starting at the new address
;          \ end word definition

F#, 14 8 bytes
Seq.last

-6 bytes thanks to aloisdg.
Strings are treated as sequences in F#, so you can use the Seq.last function to get the last character in it.

Seq.last is a function. You can remove the let s=

Retina, 10 9 bytes
(.|¶)*
$1

Try it online!

C (gcc), 31 bytes
f(int*s){gets(s),printf("%s");}

Try it online!

O_o how does this even work

I have no idea, it just works.

Impressive list of complaints from the compiler!

Caboose, 1514 bytes
Caboose hates me, because it does. There isn't any convenient string-indexing instruction in Caboose!
var a=input();print(a.endsWith(' ')and' 'or a.endsWith('!')and'!'or a.endsWith('"')and'"'or a.endsWith('#')and'#'or a.endsWith('$')and'$'or a.endsWith('%')and'%'or a.endsWith('&')and'&'or a.endsWith("'")and"'"or a.endsWith('(')and'('or a.endsWith(')')and')'or a.endsWith('*')and'*'or a.endsWith('+')and'+'or a.endsWith(',')and','or a.endsWith('-')and'-'or a.endsWith('.')and'.'or a.endsWith('/')and'/'or a.endsWith('0')and'0'or a.endsWith('1')and'1'or a.endsWith('2')and'2'or a.endsWith('3')and'3'or a.endsWith('4')and'4'or a.endsWith('5')and'5'or a.endsWith('6')and'6'or a.endsWith('7')and'7'or a.endsWith('8')and'8'or a.endsWith('9')and'9'or a.endsWith(':')and':'or a.endsWith(';')and';'or a.endsWith('<')and'<'or a.endsWith('=')and'='or a.endsWith('>')and'>'or a.endsWith('?')and'?'or a.endsWith('@')and'@'or a.endsWith('A')and'A'or a.endsWith('B')and'B'or a.endsWith('C')and'C'or a.endsWith('D')and'D'or a.endsWith('E')and'E'or a.endsWith('F')and'F'or a.endsWith('G')and'G'or a.endsWith('H')and'H'or a.endsWith('I')and'I'or a.endsWith('J')and'J'or a.endsWith('K')and'K'or a.endsWith('L')and'L'or a.endsWith('M')and'M'or a.endsWith('N')and'N'or a.endsWith('O')and'O'or a.endsWith('P')and'P'or a.endsWith('Q')and'Q'or a.endsWith('R')and'R'or a.endsWith('S')and'S'or a.endsWith('T')and'T'or a.endsWith('U')and'U'or a.endsWith('V')and'V'or a.endsWith('W')and'W'or a.endsWith('X')and'X'or a.endsWith('Y')and'Y'or a.endsWith('Z')and'Z'or a.endsWith('[')and'['or a.endsWith('\\')and'\\'or a.endsWith(']')and']'or'~');

If I add more constants, then Caboose will say that there are too many constants in the chunk. Fortunately it passes all test cases given. Basically it (tries to) check the last character against all characters in printable ASCII.
TIO

Scratch 3.0, 7 blocks/68 bytes

or, as scratchblocks syntax
when gf clicked
ask()and wait
say(letter(length of(answer))of(answer

Try it on scratch
Did I mention this was done 100% on mobile? Because it was really hard making this, but I think it was worth it.

naz, 38 bytes
2a2x1v1x1f1r3x1v2e2x2v1f0x1x2f2v1o0x1f

Works for any input string terminated with the control character STX (U+0002).
Explanation (with 0x commands removed)
2a2x1v             # Set variable 1 equal to 2
1x1f1r3x1v2e2x2v1f # Function 1
                   # Read a byte of input
                   # Jump to function 2 if it equals variable 1
                   # Otherwise, store it in variable 2,
                   # then jump back to the start of the function
1x2f2v1o           # Function 2
                   # Load variable 2 into the register and output it
1f                 # Call function 1

Ruby -pl, 9 bytes
Similar to the Perl solution, but chop doesn't return the last character in Ruby. (It instead returns the rest of the string without the last character.)
$_=$_[-1]

Try it online!

MAWP, 2 bytes
|;

Outputs top of stack.
Try it!

Flurry, 14 bytes
([]{(){}{}}{})

Run example
$ echo -n "?" | ./flurry -bnb -c "([]{(){}{}}{})"
?
$ echo -n "Hello world" | ./flurry -bnb -c "([]{(){}{}}{})"
d

-bnb flag means "print stack as chars, print nothing for return value, and take stdin as chars".
If the challenge were asking for "the last value from an integer array", I would use return value output and write 2 byte solution {} (pop the stack and return it). But since character I/O is required and the only way to output a char is via the stack, I had to manually empty the stack.
How it works
(
 []     Stack height as Church numeral; Given 2 arguments `f` `x`,
          a Church numeral `n` acts as "apply `f` `n` times to `x`"
 {      Define f, with its argument pushed to the stack:
  ()      K; Given two arguments, ignore the second
  {}      Pop; the argument
  {}      Pop; pop an extra item from the stack (ignored by K)
 }      End definition of f: Return its argument unchanged,
          popping and discarding an item from the stack
 {}     Pop an item (last char)
        At this point, the stack is empty and the value is the last char
)     Push the result of the above

Notepad, 9 5 keystrokes
Assuming the cursor is at the end of the file.
[LeftArrow][Ctrl-Shift-LeftArrow][Delete]

I know it is not a language, but I'm posting just for fun.

The input is one line, according to the challenge specs. -6 keystrokes: [LeftArrow][Ctrl-Backspace]

@hi. Doesn't work on my notepad. Ctrl-Backspace just adds an unprintable character, which I suspect is \x7f.

@hi. I don't see anything in the specs about it only being one line of input

dotcomma, 48 bytes
[[[],],][.[[[,.][.[,]].,][[,].[,]].]][,[,].[,.]]

Try it online!
Because dotcomma is queue-based, you can't easily access the last character. My solution is to reverse the input and then output the first character of it.
Code:
                # reverse the input
[[[],],]        mark the end with 0 0
[.[             while there are characters in input
  [[,.]         put a character on the recursion stack
    [.[,]]      go to reverse section
  .,]           save the character in the reverse section
  [[,].[,]]     go to input section
.]]

[               # get first character and delete all others
  ,[,]          delete 0 and append the next character (last of input) to the end of the queue
  .[,.]         delete everything until we reach a 0
]
                implicitly output the queue

dotcomma (experimental), 17 bytes
[,][[],][.[,.]].,

Try it online!
I marked this "experimental" because the language dotcomma is still very young and I don't know if this is intentional behaviour. If you pass input as a list of strings it reverses each string, so you only need to extract the first letter.
[,]      put first character on recursion stack
[[],]    put 0 (end of queue marker) on queue
[.[,.]]  delete everything from queue
.,       write back character

Wasn't even sure this was possible! Would you be fine with me copying your code snippet to a github page so I can make a try it online link generator?

I think, the language has everything it needs to be Turing complete. You can build loops, you can implement if- else statements (even easier than in other esolangs), you can calculate numbers, you can read and write data and I/O. Most things will be hard to program, but it should be able to do anything. Of course you can copy my code snippet. I'd be happy to help you gain more attention for your languages.

PS: There are different versions of that snippet in my answers, depending on what type of input and output it uses. I didn't yet manage to auto- detect the input type.

I finished my online interpreter. Also sorry it took so long, I had a lot of other projects :p

Nice. There are some minor bugs but I updated my answer using your online interpreter.

vim, 6 bytes
VGJ$d^

Annotated
VGJ     # join all lines
$       # move cursor to (before) last character
d^      # delete to beginning

Try it online!

v}hd is 2 bytes smaller.

@Razetime But it fails if the last line of input only has one character: there's nowhere for the h to go, so the last character gets included in the delete range.

ah, interesting.

Julia, 4 bytes
last

Try it online!

Damn! Of course this counts :p

Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&

Try it online!

C# (.NET Core), 81 bytes, command-line input
class M{static void Main(string[] a){System.Console.Write(a[0][a[0].Length-1]);}}

Try it online!
If you run this from an actual command line, you will need to wrap your string in quotes if it contains spaces.

C# (.NET Core), 115 bytes, console input
using C=System.Console;class M{static void Main(string[] a){int c=0,d;while((d=C.Read())>-1)c=d;C.Write((char)c);}}

Try it online!
This feels kinda janky, but it does work.  Interestingly, I can't save any bytes with a for loop as the code stands.

Perl 6, 11 bytes
*.comb[*-1]

Try it online!
Anonymous Whatever lambda that takes a string, splits it into characters, and returns the last one.

Batch, 24 bytes
@set s=%1
@echo %s:~-1%

Takes input as a command-line argument. Note that arguments can't include special characters or spaces, but you can fake arguments with spaces in this case by preceding it with a ", which results in a single argument that begins with ", however there is no easy solution for arguments that include special characters. Batch can't easily read "all of stdin". To read up to but not including the first newline itself would however be a byte shorter:
@set/ps=
@echo %s:~-1%

Edit: A version that handles arbitrary characters in a (quoted) argument for 92 bytes:
@set s="%~1"
@set "s=%s:~-2,1%
@if "%s%"=="" (echo ^")else for %%s in ("%s%")do @echo %%~s

Explanation: The first line makes a copy of the argument in a variable and ensures that it is quoted. The second argument then takes the second last character (because the quote is now the last character). However, if that was also a quote then this results in an empty variable, so we need to special-case that and output a (quoted) quote. Otherwise, we still need to quote the character in case it is a special character as echoing "%s%" will echo the quotes and echoing %s% will actually interpret special characters, so the variable needs to be quoted to allow it to be parsed but then immediately unquoted so it can be printed. This is achieved using the for command. 86 bytes to read up to but not including the first newline from stdin while supporting special characters:
@set/ps=
@set "s=%s:~-1%
@if "%s%"=="" (echo ^")else for %%s in ("%s%")do @echo %%~s

C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()

Try it online!

you can use a function :P

OK - Ill update my answer :)

uhm why is testcase in STDIN not footer

Wow - It's been a while. Thanks for pointing that out ;)

@Ven - This is an anonymous function that takes a string as input and returns a char. The OP mentions that functions are valid submissions.

Challenge also says "is non-empty."

@Ven - It says the input is non-empty. My function should work if at least 1 character is specified (i.e. non-empty). Not sure I understand your question.

That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.

Scratch 3.0, scratchblocks3 syntax
As a function, 61 bytes
define l
ask[]and wait
say(letter(length of(answer))of(answer

As a full program, 68 bytes
when gf clicked
ask[]and wait
say(letter(length of(answer))of(answer

Try both online

Befunge-98, 5 bytes
~2j@,

Try it online!
Explanation:
~           Take input
 2j         Skip next two instructions
~           Repeat until EOF, where it reflects
   @,       Print the last character and exit

Japt, 1 byte
Ì

Try it online!
-1 byte thanks to Quintec!

1 byte

Whitespace, 54 bytes
[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve_input][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_PRINT][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][S N
N
_Discard_top][T N
S S _Print_as_character]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Since Whitespace can only take input as integer or character, we must add a trailing character to indicate we're done with the input-string after reading it character by character, for which I've used a newline.
Try it online (with raw spaces, tabs and new-lines only).
Example run: input = A2#
Command    Explanation                   Stack                Heap    STDIN STDOUT STDERR

NSSN       Create Label_LOOP             []
 SSSN      Push 0                        [0]
 SNS       Duplicate top (0)             [0,0]
 TNTS      Read STDIN as character       [0]                  {0:65}  A
 TTT       Retrieve at heap address (0)  [65]                 {0:65}
 SNS       Duplicate top (65)            [65,65]              {0:65}
 SSSTSTSN  Push 10                       [65,65,10]           {0:65}
 TSST      Subtract top two (65-10)      [65,55]              {0:65}
 NTSSN     If 0: Jump to Label_PRINT     [65]                 {0:65}
 NSNN      Jump to Label_LOOP            [65]                 {0:65}

 SSSN      Push 0                        [65,0]
 SNS       Duplicate top (0)             [65,0,0]
 TNTS      Read STDIN as character       [65,0]               {0:50}  2
 TTT       Retrieve at heap address (0)  [65,50]              {0:50}
 SNS       Duplicate top (50)            [65,50,50]           {0:50}
 SSSTSTSN  Push 10                       [65,50,50,10]        {0:50}
 TSST      Subtract top two (50-10)      [65,50,40]           {0:50}
 NTSSN     If 0: Jump to Label_PRINT     [65,50]              {0:50}
 NSNN      Jump to Label_LOOP            [65,50]              {0:50}

 SSSN      Push 0                        [65,50,0]
 SNS       Duplicate top (0)             [65,50,0,0]
 TNTS      Read STDIN as character       [65,50,0]            {0:35}  #
 TTT       Retrieve at heap address (0)  [65,50,35]           {0:35}
 SNS       Duplicate top (35)            [65,50,35,35]        {0:35}
 SSSTSTSN  Push 10                       [65,50,35,35,10]     {0:35}
 TSST      Subtract top two (35-10)      [65,50,35,25]        {0:35}
 NTSSN     If 0: Jump to Label_PRINT     [65,50,35]           {0:35}
 NSNN      Jump to Label_LOOP            [65,50,35]           {0:35}

 SSSN      Push 0                        [65,50,35,0]
 SNS       Duplicate top (0)             [65,50,35,0,0]
 TNTS      Read STDIN as character       [65,50,35,0]         {0:10}  \n
 TTT       Retrieve at heap address (0)  [65,50,35,10]        {0:10}
 SNS       Duplicate top (10)            [65,50,35,10,10]     {0:10}
 SSSTSTSN  Push 10                       [65,50,35,10,10,10]  {0:10}
 TSST      Subtract top two (10-10)      [65,50,35,10,0]      {0:10}
 NTSSN     If 0: Jump to Label_PRINT     [65,50,35,10]        {0:10}

NSSSN      Create Label_PRINT            [65,50,35,10]        {0:10}
 SNN       Discard top                   [65,50,35]           {0:10}
 TNSS      Print as character to STDOUT  [65,50]              {0:10}        #
                                                              {0:10}               error

Stops with the error: Exit not defined.

Japt -h, 1 byte
U

Run it online

Runic Enchantments, 5 bytes
i1Z%@

Try it online!
Note that input handling in Runic has implicit conversion and breaks on spaces. \ denotes a literal space (works on newlines too) and numerical values are never strings.

Binary-Encoded Golfical, 17 bytes
Hex-dump of binary encoded file:
00 60 02 1b 1a 08 01 14
16 14 24 1d 0a 01 14 18
14

Original image:

Magnified 45x with colors labeled:

The original image (the tiny one, not the magnified version) can be run using the interpreter normally. The binary encoded file (of which a hexdump is included above) can either be transpiled back to the image version with the Encoder program included in the github repo, or run directly using the interpreter by adding the -x flag.

Chip -z, 41 bytes
S
>vvvvvv~t
ABCDEFG
|Zz||Zz
zbcZzfg
a  de

Try it online!
Assumes that either the byte string does not contain zero (\0), or that it designates the end of the string.

Alternate solution (45 bytes):
azABZbczCDZdezEFZfgzG
S-^^----^^----^^----^~t

Try it online!

R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)

Try it online!

Simple trick to save 1 byte

32 bytes.

Japt -h, 1 byte
Can handle input as a string, integer or character/digit array.
s

Try it

C, 36 35 34 bytes
x(char*v){printf(v+strlen(v)-1);}

Really simple stuff here. Nothing to ungolf either.
Saved one byte thanks to ceilingcat
Fixed the answer and saved another byte thanks to ASCII-only

Haskell, 4 bytes
last

Functions are allowed, right?
Also with IO (18 bytes):
main=interact$last

The same answer was already posted, though we do allow duplicate answers as far as I know.

Pepe, 13 bytes
REEeREEEeReEe

Try it online! Disable "Separated by" check box below the input text box.
Explanation:
REEe  # Input as string (stack R)
REEEe # Goto last char (stack R)
ReEe  # Output char (stack R)

Triangular, 10 bytes
(#~p../)?<

Try it online!
Pretty straight-forward; reads characters until it gets a null read, then prints the top of the stack.
Ungolfed:
   (
  # ~
 p . .
/ ) ? <
--------------------------------------------
(            Set a point to jump back to
 ~.<         Read a character, change directions ("." is a no-op)
    ?)/      If ToS <= 0, skip next instruction and change directions; otherwise, jump back to "("
       p#    Pop the top value from the stack (the null input), then pop again and print that value

Commodore 8-bit BASIC (CBM/PET, VIC-20, C64/TheC64Mini, C128, C16/+4) - byte count later
 0inputa$:iflen(a$)thenprintright$(a$,1)

Simplified (without the sanity check):
 0inputa$:?right$(a$,1)

There is a small limitation in that Commodore 8-bit BASIC the maximum length of a string is 255 characters, so any entry above that will cause an error.

Keg, 1 byte
This is the exact thing that Keg was built for.
,

Explanation
# Push implicit string input
,# Output the last pushed character
# There is no implicit output since something was outputted

TIO

Brain-Flak-cr, (6 bytes code + 3 bytes command line) = 9 bytes
({}<>)

Try it online!
Code:
The command line argument "-cr" means "use ASCII input and output" and "reverse the stack", so when you pop a value, the last byte of the input is popped, and when you push a value, it is pushed to the end.
 {}     pop a character
(    )  and push it
   <>   on the other stack
        implicitly output the current stack

MarioLANG, 18 bytes
>,
"+
)[
!<(-
#==.

Try it online!
code:
>    go right
,    read input
+    increment it (because EOF = -1)
[    ignore the next command, if current cell = 0
<    go to the left
!    stop moving (Mario is now standing on the elevator (#),
     which rides up to the elevator end (")
)    go to the next memory cell
     Mario is now at the starting position (>) and runs another round
     until the end of input

else (if he ignored the "<" instruction)
(    go one memory cell back (to the last inputted byte)
-    decrement it, so it becomes the original value again
.    print it

Clojure, 32 bytes 24 bytes
(print(last(read-line)))

(print             ;; prints output
  (last            ;; get last character of input
    (read-line)))  ;; read input

Try it online!

You could shave off 3 bytes by removing all whitespace. It also seems like you don't need the str, but my Clojure is extremely rusty so I can't say for sure.

@UnrelatedString I don't know that I can use without whitespace at all. Thanks for that.
I think str is not needed at all, but it will return char (\?) instead of string ("?") (if that's okay)

GolfScript, 3 bytes
The GolfScript = yields a decimal. That's pretty weird ... However, (luckily enough,) GolfScript supports slicing over a string, which allows me to slice the last item of the string.
-1>

Try it online!
Explanation
-1  # The last item
  > # Choose everything in the string
    # after the last item, including the last item
    # this (obviously) yields the last item

GolfScript, 3 bytes
Though there was already a Golfscript 3 byte solution, I figured I'd throw in the more general-purpose one.
)\;

Where ( is the front-uncon function (Golfscript treats strings as char arrays), \ swaps the string and char positions, and ; deletes the string, leaving only the last char.

Sure is not ) what you intended to use? At least with the interpreter available on tio.run this outputs the first byte, not the last.

That's exactly what I meant - thank you, accidentally copy/pasted from the wrong solution file :)

APL (Dyalog Unicode), 2 bytesSBCS
⊢/

Try it online!
The code taken literally means to "reduce by right argument function". It works like the following (basically like foldr1 (flip const) in Haskell):
  ⊢/ 'abcd'
→ 'a' ⊢ 'b' ⊢ 'c' ⊢ 'd'
→ 'a' ⊢ 'b' ⊢ 'd'
→ 'a' ⊢ 'd'
→ 'd'

This is an idiom for taking last element from a vector (or taking last element from each row of a multi-dimensional array).

Burlesque, 2 bytes
[~

Try it online!
If it needs to be pretty formatted [~Q
[~ # Last char

Integral, 2 Bytes

Vn

Try it!
Explanation
V  Reverse the input
 n Head

Pip, 4 bytes
a@-1

@RVa also works, and is the same size.
Try it online!

Marbelous, 13 bytes
@0
00
]]..
@0

Marbelous is a language based on marble machines

@n (n from 0 to Z) is a portal which teleport the marble to another portal with the same value
00-FF initiate a marble with this value
]] passing marble take value of next input byte if there is one, else the marble is diverted to the right
.. is a noop
marbles going out of the board to the bottom are implicitly outputed

interpretor

Labyrinth, 8 bytes
,);.@
"(

Try it online!
,)("  Loop until EOF (-1): push a char input, increment, then decrement
;.@   On EOF, discard top, print the last char, and halt

Same bytecount, but a little simpler. I don't think a T intersection can be made any smaller

Pyth, 1 byte
e

Try it online!

Regex, 2 bytes
.$

Matches character then end of string.

APOL, 7 bytes
g(i -1)
About as simple as possible, just gets the last character of the input string.

Fig, \$1\log_{256}(96)\approx\$ 0.823 bytes
]

Try it online!
1-byters?? Seriously?? Why have that when you can have 0.823 bytes?? Literally "grab last char of (implicit) input."

Hey that ain't fair :(

nroff, 57 bytes
.de F
.ds X \\$1
.length L \\*X
.substring X \\nL
\\*X
..

Attempt This Online!
Usage
.F "41382239"
.F "e"
.F "what"
.F " a "
.F "b c"

How it works
.de F             \" define macro F
.ds X \\$1        \" store 1st argument to string variable X
                  \" I had to do so because arguments are not in variable, but
                  \" can be obtained via requests only
.length L \\*X    \" store length of X to register L
                  \" no numerical express to do so
.substring X \\nL \" 1-indexed. replace X with L-th to last substring
\\*X              \" content of X
..                \" end of definition

AArch64 machine code, 12 bytes
20 8c c0 28 e3 ff ff 35 c0 03 5f d6

Commented assembly
    .globl lastchar
    // Input: x1: null terminated UTF-32 string
    // Output: w0: last char in string
    // char32_t lastchar(int dummy, const char32_t *str);
lastchar:
.Lloop:
    // load two chars, advance by one char
    // w0 = *x1++; w3 = *x1;
    ldp     w0, w3, [x1], #4
    // loop if w3 was not zero (null terminator)
    cbnz    w3, .Lloop
    // return
    // result is in w0
    ret

This can be called from C using a dummy parameter to put the null terminated UTF-32 string in x1.
char32_t lastchar(int dummy /* x0 */, const char32_t *ptr /* x1 */);

I don't usually do AArch64 because it isn't very compact at 4 bytes per instruction and almost always longer than Thumb, but this particular solution is really elegant even if it is larger than the equivalent Thumb code by 2 bytes (it's solely because of the return instruction being 2 bytes) (Thumb does better with ptr+length though)

ARM Thumb machine code, 6 bytes
01 39 40 5c 70 47

Commented assembly:
    .syntax unified
    .arch armv7-a
    .thumb
    .globl lastchar
    .thumb_func
    // C-callable function
    // Input:
    //  - r0: String of ASCII (not utf-32)
    //  - r1: Length of string
    // Output:
    //  - r0: Char
    // int lastchar(const char *ptr, uint32_t length);
lastchar:
    // It's literally ptr[length - 1]
    // Subtract 1 from the length since ARM can't do [reg, reg, offset]
    subs    r1, #1
    // load ptr[length]
    ldrb    r0, [r0, r1]
    // return in r0
    bx      lr

I mean it is literally return ptr[length - 1], there isn't much to explain. The function is callable using the C convention, using byte string + length (not null-terminated UTF-32 like most of my solutions):
int lastchar(const char *ptr, uint32_t length);

ARM Thumb machine code, 10 bytes
This is the "equivalent Thumb code" I mentioned on my aarch64 answer. It is much less elegant.
01 c9 0b 68 00 2b fb d1 70 47

Commented assembly:
    .syntax unified
    .arch armv7-a
    .thumb
    .globl lastchar
    .thumb_func
    // C-callable function
    // Input:
    //  - r1: Null terminated UTF-32LE string
    // Output:
    //  - r0: Char
    // char32_t lastchar(int dummy, const char32_t *str);
lastchar:
.Lloop:
    // load 1 char, advance pointer
    ldmia   r1!, {r0}
    // Load next char into temp
    ldr     r3, [r1]
    // compare and loop if r3 wasn't a null terminator
    cmp     r3, #0
    bne     .Lloop
    // return in r0
    bx      lr

This uses the same function signature, taking a null terminated UTF-32 string and a dummy parameter to put str in r1:
char32_t lastchar(int dummy /* r0 */, const char32_t *str /* r1 */);

In an ideal world, the direct equivalent could be done:
lastchar:
.Lloop:
    ldrd    r0, r3, [r1], #4
    cbnz    r3, .Lloop
    bx      lr

But unfortunately:

ldrd will bus error if the pointer is not 8 byte aligned (even with unaligned access support), and advancing the pointer by 4 will end up unaligned.
ldmia always advanced by 4 * NumRegisters
cbnz can only branch forwards

Python 3, 16 bytes
This is a pretty basic answer, but I think that it is the lowest Python 3 can go...
x=lambda a:a[-1]

TIO

you don't need the x= here

T-SQL, 23 bytes
SELECT RIGHT(v,1)FROM i

Didn't see a SQL solution yet.
Input is via a pre-existing table \$i\$ with varchar field \$v\$, per our IO rules.

Perl 5, 7 bytes
$_=chop

This must be executed using the -pe flags.
Example
$ echo -n "abcd" | perl -pe '$_=chop'
d

Explanation
The -p flag wraps code inside a block that appears as:
while (<>) { ... ; print } whereas the '...' would include the code provided. The entire script would expand to:
while (<>) { $_ = chop ; print }

What I did here was set the context variable $_ to the return value of chop, which returns the last character of a string. Shortly after, print with no statements on its own will display the previously assigned context variable.

Zsh, 11 bytes
try it online!!
<<<${1: -1}

clone of the bash answer, 2 bytes shorter

Pushy, 1 byte
'

Try it online!
Print the top of stack as a character!

Scala, 6 bytes
_.last

Try it online!
Not much to say here - it's just a function that takes a string (or really any iterable) and outputs its last element.

MathGolf, 2 bytes
┤Þ

Try it online.
Or alternatively:
b§

Try it online.
Explanation:
┤   # Pop the left character of the (implicit) input-string loose to the stack
 Þ  # Only leave the top item of the stack, and discard everything else
    # (implicitly output the entire stack joined together)

b   # Push -1
 §  # Get the -1'th character of the (implicit) input-string
    # (0-based modulair similar as Python, so will index into the last character)
    # (implicitly output the entire stack joined together)

Rockstar, 30 bytes
listen to S
cut S
say S at S-1

Try it here (Code will need to be pasted in)
Or 51 bytes if we need to be able to handle newlines in the input:
listen to S
while S
listen to S

cut S
say S at S-1

05AB1E, 1 byte
θ

Try it online!
   # (implicit) push STDIN to stack
θ  # push last character of top of stack
   # (implicit) output top of stack to STDOUT

CSASM v2.2.1.1, 46 bytes
func main:
in ""
push ^1
push ^0
substr
print
ret
end

Commented:
func main:
    ; Get the input
    in ""
    ; Get a substring of the input from (length - 1) to (length - 0)
    push ^1
    push ^0
    substr
    ; Print it
    print
    ret
end

Duocentehexaquinquagesimal, 3 bytes
t`F

Try it online!

J, 2 bytes
{:

{: is implicit verb for last element of any array (including strings)
Try it online!

Factor, 11 bytes
[ 1 tail* ]

Try it online!

M4, 36 bytes
define(f,`substr($1,decr(len($1)))')

Attempt This Online!

Brainfuck, 11 bytes
,>+[-,>+]<.

Explained:
,> [ ,> ]   get input
  + -  +    sentinels
         <. output last non-NUL byte (NUL doesn't count, doesn't it?)

MAWP, 2 bytes
|;

Try it!
Explanation:
|      take whole input onto stack as ASCII value
 ;     output top of stack

Go, 38 bytes
func(s []byte)byte{return s[len(s)-1]}

Attempt This Online!

Standard ML, 8 bytes
There are two common ways of string processing: char lists and strings. In both cases, the underlying char is an 8 bit value using "extended ASCII".
For char lists:
hd o rev

I'm not sure why List.last isn't top-level, but that works too.
For strings, convert to List and use explode:
hd o rev o explode

Vyxal, 1 byte
t

Try it Online!

JavaScript (Node.js), 10 bytes
Assumes every byte is a letter one of 0 through 9.
Is this justified?
s=>s%10+""

Attempt This Online!

Thunno 2 t, 0 bytes

Attempt This Online!
That's right: no bytes. The t flag does all the work.
Or 1 byte flagless:
t

Attempt This Online!
Built-in for last item.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Which were the latest 13 consecutive years with the most friday 13. in total?
Shortest program wins, of course.

You may want to try "The Sandbox" for future challenges. Also, include the challenge in the body, with a very short title. Are we supposed to take the current time as input or get it via a date function? Are the consecutive thirteen years within 0-the current year? Can the current year be included in the 13 consecutive years? What should our program return if there is a tie between two different thirteen consecutive years?

And what stops submissions from just hardcoding it?

I suppose it depends on whether it actually needs to depend on the date it's run on or if it's actually meant to be [tag:kolmogorov-complexity]... which is a difficult question to resolve (along with output format and just about everything else) when the body is shorter than the title.

Wolfram Language 171 bytes
Any modern 13-year interval will have between 20 and 24 Friday the 13ths.
SortBy[{{#[[1,1]],#[[-1,1]]},Total[#[[2]]&/@#]}&/@Partition[Table[{y,Length@Cases[DateObject@{y,m,13}~Table~{m,12},x_/;DayName@x==Friday]},{y,1900,2019}],13,1],Last][[-1]]

* {{2007, 2019}, 24} *)

The above generates all the Friday the 13ths for each year between 1900 and 2019, partitions the results into intervals of 13 years, and finds the total for each such interval.  The interval of 2007-2019 has 24, the maximum number of Friday the 13ths.
If 2019 cannot be used, the correct answer will be the interval of 200-2018, which also contains 24 Friday the 13ths.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Output visual diagram of picture
Write a program that inputs the dimensions of a painting, the matting width, and the frame width for a framed portrait. The program should output a diagram using the symbol X for the painting, + for the matting, and # for the framing. The symbols must be space-separated. Trailing whitespace is alright, as long as the output visually matches the criteria. The inputs can be 0.
INPUT: 3 2 1 2
(Width, Height, Matte Width, Frame Width)
OUTPUT:

In text form:
# # # # # # # # #
# # # # # # # # #
# # + + + + + # #
# # + X X X + # #
# # + X X X + # #
# # + + + + + # #
# # # # # # # # #
# # # # # # # # #

The winning code completes the conditions in the least possible bytes.

Nice challenge! For future challenges you may want to use The Sandbox

Also, will the frame height be given?

MilkyWay90, the frame is a constant width around the portrait so only one value is needed.

Thanks! Is the constant width always 2 (or is it the height of the frame)?

Well, the program should be able to handle any case, no? Typically it should be assumed any of the numbers are subject to change. Just given the four inputs, you must produce the visual output. :)

Okay! I will take this into account

It feels oddly satisfying to delete whole sections of my code while golfing this

do you mind if the input is in a different order?

Can we return a list of strings?

Can any of the inputs be zero?

Can we have an space at the end of each line?

So... I guess the question is kinda late, but have you taken this challenge from somewhere else? If so, you should attribute the source.

Yes, the inputs can be 0. There is no specific order to the inputs that is required. There may be a space at the end of the lines, and this is an original idea for all I know. I have searched online and I can't seem to find a similar question.

Python 2, 98 bytes
w,h,a,b=input()
a*='+'
b*='#'
for c in b+a+h*'X'+a+b:print' '.join(min(c,d)for d in b+a+w*'X'+a+b)

Try it online!
Prints a space-separated grid, strictly following the spec. I'm amused that *= is used to convert a and b from numbers to strings.
Python 3 can save some bytes by avoiding ' '.join, maybe more by using f-strings and assignment expressions. Thanks to Jo King for -2 bytes.
Python 3, 93 bytes
def f(w,h,a,b):a*='+';b*='#';[print(*[min(c,d)for d in b+a+w*'X'+a+b])for c in b+a+h*'X'+a+b]

Try it online!

I've been outgolfed! NIce job, seems pretty golfed

Nice golf! Very clever.

JavaScript (ES6),  118 113  107 bytes
(w,h,M,F)=>(g=(c,n)=>'01210'.replace(/./g,i=>c(i).repeat([F,M,n][i])))(y=>g(x=>'#+X'[x<y?x:y]+' ',w)+`
`,h)

Try it online!
Commented
(w, h, M, F) => (       // given the 4 input variables
  g = (                 // g = helper function taking:
    c,                  //   c = callback function returning a string to repeat
    n                   //   n = number of times the painting part must be repeated
  ) =>                  //
    '01210'             // string describing the picture structure, with:
    .replace(           //   0 = frame, 1 = matte, 2 = painting
      /./g,             // for each character in the above string:
      i =>              //   i = identifier of the current area
        c(i)            //   invoke the callback function
        .repeat         //   and repeat the result ...
        ([F, M, n][i])  //   ... either F, M or n times
    )                   // end of replace()
)(                      // outer call to g:
  y =>                  //   callback function taking y:
    g(                  //     inner call to g:
      x =>              //       callback function taking x:
        '#+X'           //         figure out which character to use
        [x < y ? x : y] //         according to the current position
        + ' ',          //         append a space
      w                 //       repeat the painting part w times
    )                   //     end of inner call
    + '\n',             //     append a line feed
  h                     //   repeat the painting part h times
)                       // end of outer call

MATL, 24 bytes
&l,ithYaQ]'#+X'w)TFX*cYv

Input is: Height, Width, Matte Width, Frame Width.
Try it online!
Explanation
&l      % Take height and width implicitly. Push matrix of that size with all
        % entries equal to 1
,       % Do twice
  i     %   Take input
  th    %   Duplicate, concatenate: gives a 1×2 vector with the number repeated
  Ya    %   Pad matrix with those many zeros vertically and horizontally
  Q     %   Add 1 to each entry
]       % End
'#+X'   % Push this string
w)      % Index into the string with the padded matrix
TF      % Push row vector [1 0]
X*      % Kronecker product. This inserts columns of zeros
c       % Convert to char again. Char 0 is will be displayed as space
Yv      % Remove trailing spaces in each line. Implicitly display

Charcoal, 48 47 44 bytes
≔×ＮXθ≔×ＮXηＦＥ+#×Ｎι«≔⁺ι⁺θιθ≔⁺ι⁺ηιη»Ｅη⪫⭆θ⌊⟦ιλ⟧

Try it online! Link is to verbose version of code. Note: Trailing space. Edit: Now uses @xnor's algorithm. Explanation:
≔×ＮXθ≔×ＮXη

Input the width and height and convert them into strings of Xs.
ＦＥ+#×Ｎι

Loop over the characters + and #, converting them into strings of length given by the remaining two inputs. Then loop over those two strings.
«≔⁺ι⁺θιθ≔⁺ι⁺ηιη»

Prefix and suffix the painting with the strings for the matting and framing.
Ｅη⪫⭆θ⌊⟦ιλ⟧

Loop over the strings, taking the minimum of the horizontal and vertical characters, and then double-spacing the rows, implicitly printing each row on its own line.

Wolfram Language (Mathematica), 142 bytes
(t=(p=Table)["# ",2(c=#4+#3)+#2,2c+#];p[t[[i,j]]="+ ",{j,z=#4+1,c+#3+#},{i,z,c+#3+#2}];p[t[[i,j]]="X ",{j,#3+z,c+#},{i,#3+z,c+#2}];""<>#&/@t)&

Try it online!

05AB1E (legacy) / 05AB1E --no-lazy, 32 31 bytes
и'X×„+#vyI©×UεX.ø}®FDнgy×.ø]€S»

Takes the input in the order height, width, matte, frame. If the input order specified in the challenge is strict (still waiting on OP for verification), a leading s (swap) can be added for +1 byte.
Required the --no-lazy Elixir compiler flag in the new version of 05AB1E, since Elixir has some odd behavior due to lazy evaluation for nested maps/loops (here the result without this flag).
Try it online in the legacy version of 05AB1E.
Try it online in the new version of 05AB1E with added --no-lazy flag.
Explanation:
и              # Repeat the second (implicit) input the first (implicit) input amount of
               # times as list
 'X×          '# Repeat "X" that many times
„+#v           # Loop `y` over the characters ["+","#"]:
    y          #  Push character `y`
     I         #  Push the next input (matte in the first iteration; frame in the second)
      ©        #  And store it in the register (without popping)
       ×       #  Repeat character `y` that input amount of times
        U      #  Pop and store that string in variable `X`
    εX.ø}      #  Surround each string in the list with string `X`
    ®F         #  Inner loop the value from the register amount of times:
      Dнg      #   Get the new width by taking the length of the first string
         y×    #   Repeat character `y` that many times
           .ø  #   And surround the list with this leading and trailing string
   ]           # Close both the inner and outer loops
    €S         # Convert each inner string to a list of characters
      »        # Join every list of characters by spaces, and then every string by newlines
               # (and output the result implicitly)

Jelly, 17 bytes
;ŒB“#+X+#”xʋⱮ«Ɱ/G

Try it online!
Argument 1: [Frame width, Matte width]
Argument 2: [Width, Height]

Python 3.8 (pre-release), 116 115 113 bytes
lambda a,b,c,d:"\n".join((g:=['#'*(a+2*c+2*d)]*d+[(h:='#'*d)+'+'*(a+c*2)+h]*c)+[h+'+'*c+'X'*a+'+'*c+h]*b+g[::-1])

Try it online!
First attempt at golfing, will be improved soon.
a is width, b is height, c is matte width, and d is frame width.
-1 bytes using the := operator to define h as e * d
-2 bytes thanks to Jo King suggesting me to remove the e and f parameters
EXPLANATION:
lambda a,b,c,d:          Define a lambda which takes in arguments a, b, c, and d (The width of the painting, the height of the painting, the padding of the matte, and the padding of the frame width, respectively).
    "\n".join(                       Turn the list into a string, where each element is separated by newlines
        (g:=                         Define g as (while still evaling the lists)...
            ['#'*(a+2*c+2*d)]*d+       Form the top rows (the ones filled with hashtags)
            [(h:='#'*d)+'+'*(a+c*2)+h]*c Form the middle-top rows (uses := to golf this section)
        )+
        [h+'+'*c+'X'*a+'+'*c+h]*b+       Form the middle row
        g[::-1]                      Uses g to golf the code (forms the entire middle-bottom-to-bottom)
    )

Removing the e assignment saves you two bytes, the f assignment isn't saving you anything

@JoKing Oh wow, I forgot to remove the e and f assignments after discovering the g shortcut

Jelly, 35 31 28 24 bytes
Dịx@“#+X+#”
⁽-Fç«þ⁽-ȥç$G

Try it online!
Takes the input in the order frame, matte, width, height; comma separated. Outputs the ASCII-art picture with frame and matte. If the input order is strict I’d need to add more bytes (as per my original post).
Couple of golfs based on @EriktheOutgolfer’s answer; I’d realised the characters were in ASCII order but hadn’t thought how best to take advantage of that, and had forgotten about G. His is still a better answer though!

I never program in Jelly, but surely 43134,43234 can be compressed? EDIT: I need to learn to read, you mention they can indeed be encoded in 4 bytes each. But what has the input-order to do with whether these numbers can be encoded or not? :S

@KevinCruijssen the maximum integer that can be encoded using the two byte syntax is 32250; since both exceed that I can’t save the bytes. For now I’ll assume I can swap things around and revert if it’s not allowed!

Ah ok, I see. 43134 will need 3 encoding characters, which including a leading/trailing character to indicate it's encoded will be 5 bytes as well. And does Jelly perhaps have a duplicate of some sort, since the second number is 100 larger than the first? Not sure if the actions push 43134, duplicate, push 100, plus, pair is possible and shorter in Jelly?

@KevinCruijssen I originally tried that using +0,100 which doesn’t save any. I think I could use a nilad chain to use the fact that in a nilad ³ is 100, but if I’m allowed to reorder inputs the base 250 integers are better

Canvas, 24 bytes
Ｘ；«［ｌｘ＊ｅ⤢｝
X×＊+⁸#⁸ ＊Ｊ ×Ｏ

Try it here!
Should be 5 bytes shorter, but isn't because Canvas is buggy..

R, 119 bytes
function(w,h,m,f)write(Reduce(function(x,y)rbind(y,cbind(y,x,y),y),rep(c("+","#"),c(m,f)),matrix("X",w,h)),1,w+2*f+2*m)

Try it online!

Husk, 29 25 bytes
mm;₁'#⁰₁'+²RR'X
‼‼(m↔Tm+R

Try it online!
Ah, this was convoluted.
The input order is Matte,Frame,Width,Height.
-4 bytes after simplifying function 2 & 3.
Explanation
Function ₁: framing function
‼‼(m↔Tm+R parameters a(char),n(int),m(matrix)
      m+R add a side
     T    Transpose
   m↔     reverse each row
‼‼(       repeat that 3 more times

Function ₀: main
mm;₁'#⁰₁'+²RR'X
           RR'X make width × height matrix of 'X'es
       ₁'+²     add the matte of '+'es
   ₁'#⁰         add the frame of '#'es
mm;             nest each character(adds spaces)

Javascript, 158 bytes
(w,h,m,f)=>(q="repeat",(z=("#"[q](w+2*(m+f)))+`
`)[q](f))+(x=((e="#"[q](f))+(r="+"[q](m))+(t="+"[q](w))+r+e+`
`)[q](m))+(e+r+"X"[q](w)+r+e+`
`)[q](h)+x+z)

Can probably be trimmed down a little bit

f=

(w,h,m,f)=>(q="repeat",(z=("# "[q](w+2*(m+f))+`
`)[q](f))+(x=((e="# "[q](f))+(r="+ "[q](m))+(t="+ "[q](w))+r+e+`
`)[q](m))+(e+r+"X "[q](w)+r+e+`
`)[q](h)+x+z)

console.log(f(3,2,1,2))

Perl 6, 98 bytes
{map(&min,[X] map (($_='#'x$^d~'+'x$^c)~'X'x*~.flip).comb,$^a,$^b).rotor($b+2*($c+$d)).join("\n")}

Try it online!
This is a port of xnor's Python answer.
Perl 6, 115 bytes
->\a,\b,\c,\d{$_=['#'xx$!*2+a]xx($!=c+d)*2+b;.[d..^*-d;d..^a+$!+c]='+'xx*;.[$!..^*-$!;$!..^a+$!]='X'xx*;.join("
")}

Try it online!
Roughly golfed anonymous codeblock utilising Perl 6's multi-dimensional list assignment. For example, @a[1;2] = 'X'; will assign 'X' to the element with index 2 from the list with index 1, and @a[1,2,3;3,4,5]='X'xx 9; will replace all the elements with indexes 3,4,5 of the lists with indexes 1,2,3 with 'X'.
Explanation:
First, we initialise the list as a a+2*(c+d) by b+2*(c+d) rectangle of #s.
$_=['#'xx$!*2+a]xx($!=c+d)*2+a;
State:
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #

Then we assign the inner rectangle of +s
.[d..^*-d;d..^a+$!+c]='+'xx*;
State:
# # # # # # # # #
# # # # # # # # #
# # + + + + + # #
# # + + + + + # #
# # + + + + + # #
# # + + + + + # #
# # # # # # # # #
# # # # # # # # #

Finally, the innermost rectangle of Xs.
.[$!..^*-$!;$!..^a+$!]='X'xx*;
# # # # # # # # #
# # # # # # # # #
# # + + + + + # #
# # + X X X + # #
# # + X X X + # #
# # + + + + + # #
# # # # # # # # #
# # # # # # # # #

Perl 5, 115 bytes
$_=(X x$F[0].$/)x$F[1];sub F{s,^|\z,/.*/;$_[0]x"@+".$/,ge,s/^|(?=
)/$_[0]/gm while$_[1]--}F('+',$F[2]);F('#',$F[3])

TIO

PowerShell, 132 bytes
param($w,$h,$m,$f)filter l{"$(,'#'*$f+,$_[0]*$m+,$_[1]*$w+,$_[0]*$m+,'#'*$f)"}($a=@('##'|l)*$f)
($b=@('++'|l)*$m)
@('+X'|l)*$h
$b
$a

Try it online!


text:
Offset in split text content
You will be given an ASCII text. This text may have zero, one or many appearances of a split a character (let's assume it will be the space character )
You will also be given an offset integer value (zero based) anywhere between zero and the length of the text.
You should calculate the relative offset inside the one split text, which contains the absolute offset, as well as the index of that very split text.
If the given offset is at the split character the last split should have the offset
It's hard to describe (comments welcome), so here are some examples
text: Lorem ipsum dolor sit amet
offset: 20

Lorem ipsum dolor sit amet
enter code here
--------------------^
000000000011111111112
012345678901234567890

Result: 2, 3
Explanation: If we split the text along the space characters, the split text, where the offset is in, is the fragment `sit` which is the 3rd split (count starts at zero) and the offset inside this fragment is 2
sit
--^
012

Some more examples
Text                           Offset        Result
Lorem ipsum dolor sit amet     0             0, 0
^
Lorem ipsum dolor sit amet     1             1, 0
-^
Lorem ipsum dolor sit amet     2             2, 0
--^
Lorem ipsum dolor sit amet     3             3, 0
---^
Lorem ipsum dolor sit amet     4             4, 0
----^
Lorem ipsum dolor sit amet     5             5, 0
-----^
Lorem ipsum dolor sit amet     6             0, 1
------^
Lorem ipsum dolor sit amet     7             1, 1
-------^
Lorem ipsum dolor sit amet     8             2, 1
--------^
Lorem ipsum dolor sit amet     9             3, 1
---------^
Lorem ipsum dolor sit amet     10            4, 1
----------^
Lorem ipsum dolor sit amet     11            5, 1
-----------^
Lorem ipsum dolor sit amet     12            0, 2
------------^
Lorem ipsum dolor sit amet     13            1, 2
-------------^
Lorem ipsum dolor sit amet     14            2, 2
--------------^
Lorem ipsum dolor sit amet     15            3, 2
---------------^
Lorem ipsum dolor sit amet     16            4, 2
----------------^
Lorem ipsum dolor sit amet     17            5, 2
-----------------^
Lorem ipsum dolor sit amet     18            0, 3
------------------^
Lorem ipsum dolor sit amet     19            1, 3
-------------------^
Lorem ipsum dolor sit amet     20            2, 3
--------------------^
Lorem ipsum dolor sit amet     21            3, 3
---------------------^
Lorem ipsum dolor sit amet     22            0, 4
----------------------^
Lorem ipsum dolor sit amet     23            1, 4
-----------------------^
Lorem ipsum dolor sit amet     24            2, 4
------------------------^
Lorem ipsum dolor sit amet     25            3, 4
-------------------------^
Lorem ipsum dolor sit amet     26            4, 4
--------------------------^

If I am correctly interpreting your example, the second integer is the number of split characters in the first offset characters, the first is the character that is hit inside the chunk counted from its own origin? Do the two have anything in common?

@JonathanFrech I assume your thought on the second integer is correct. I don't understand your thought on the first character. And what do you mean by Do the two have anything in common??

To me, the question appears to simply be two properties of a piece of text mangled together; I wanted to ask if there is any semantic connection between the two output integers.

You want to now the reason why I ask this? It's inspired by this question on SE: https://stackoverflow.com/questions/55235774/text-area-getting-accurate-cursor-position-on-resize And I thought it would be an interesting question on CG

Can we use 1 indexed instead of 0 indexed

I'd prefer 0 but I'm not bound to it

"It's hard to describe (comments welcome)". This is why the Sandbox exists. When you want to create challenges, first lay them in the sandbox and let other people help you refine it.

Python 3.8, 56 bytes
lambda a,b:(x:=a[:b].split(' '))and[len(x[-1]),len(x)-1]

Try it online!

Perl  5, 47 44 bytes
$_=substr$_,0,<>;/.* /;$_=$'=~y///c.$".y/ //

$_=substr$_,0,<>; to extract first n (from nextline <>) characters of input $_ and store in default argument.
/.* / to match largest string ending with space
$_=$'=~y///c.$".y/ // default argument $_ (which will be printed -p option) is set with concatenation . of length of post-match : $'=~y///c, $" space (list argument delimiter when interpolated betwen double quotes), and y/ // number of spaces in current default argument.

TIO

Oh wow! How very cryptic of you

Stax, 5 bytes
╓ò)♣*

Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
(       trim string to length
j       split on spaces
N       remove last element from array and push separately
W       until the stack is empty...
  %P    pop element and print its length

Run this one

05AB1E, 9 bytes
£ð¡¤gsg<‚

Port of @JonasAusevicius's Python 3.8 answer, so make sure to upvote him as well!
Try it online or verify all test cases.
Explanation:
£         # Only leave the first (implicit) input-integer amount of characters
          #  of the (implicit) string-input
 ð¡       # Split this by spaces
          # (Note: builtin `#` doesn't work here, because a string without spaces
          #  would not be wrapped in a list)
   ¤g     # Get the length of the last string in the list (without popping the list itself)
     sg<  # Swap to get the list again, and get it's length minus 1
        ‚ # Pair both integers (and output the result implicitly)

JavaScript (Node.js), 75 70 69 70 68 67 bytes
t=>o=>[o+~(s=t.substr(0,o)).lastIndexOf(' '),s.split(' ').length-1]

Try it online!
No space parameter, only hardcoded (+ 2 bytes)
-2 bytes thanks to inspiration from the Java answer by Kevin Cruijssen
-1 byte thanks to zevee

o-s.lastIndexOf(d)-1 can be o+~s.lastIndexOf(d) to save a byte (here the relevant tip).

Also, you take the space as input, but all the others answers thus far hardcoded the space. So either the challenge should mention a third split-character is required as input, or this answer could also hardcode the space. Not sure which of the two you intended when you made the challenge?

@KevinCruijssen I used a hardcoded space now

You can do t=>o=> instead of (t,o)=> to save a byte and then take input as f(t)(o)

C# (Visual C# Interactive Compiler), 79 77 75 63 60 bytes
a=>b=>((a=a.Substring(0,b).Split())[b=a.Length-1].Length,b);

8 bytes saved thanks to Kevin Cruijssen and a further 3 bytes saved thanks to Embodiment of Ignorance
Try it online!

73 bytes

Cut another 10 using dynamic and saving the extra split

Oh smart! I need to remember that.

60 bytes: https://tio.run/##ldO9DoIwFIbh3atonNoEDaf@B2F0YnNwMA4Fq54ECqFl8OoRjBfgN7Rp05N3edLSL0rPw6l35fH@dqbmMvpe2IVITtu4VJaJh0gHk2ZFmklpUrM894UPHbunjKNCLc9txUEqdS3Gt9y6Z3gt6PY7jQPJkIjZ7NJxsDk7Kx9ynjedrQW3vq/FvamaTngOwtQ2zJWMlUr@n6ZxGohrKL7C4msovsHiWyi@w@J7KH7A4gSKgqSEmRKISpgqgayEuRIIS5gsgbQao9Xob8VoNUirMVoN0uqJdvgA

APL+WIN, 33 bytes
(1++/m),n-¯1↑(m←(m←n↑⎕)=' ')/⍳n←⎕

Try it online! Courtesy of Dyalog Classic
1 Indexed
Prompts for index of character in full text string followed by string
Outputs index of character in nth substring and substring number

Java 8, 83 75 bytes
n->s->n+~(s=s.substring(0,n)).lastIndexOf(" ")+","+~-s.split(" ",-1).length

-8 bytes implicitly thanks to inspiration from @yunzen's JavaScript answer.
Try it online.
Explanation:
n->s->                   // Method with integer & String parameters and String return-type
  n+~                    //  Return `n` minus 1, minus the following:
     (s=s.substring(0,n))//   Set `s` to the first `n` characters of input-String `s`
      .lastIndexOf(" ")  //   and get the index of the last space
  +","                   //  Appended with a comma-delimiter
     s.split(" ",        //  Split the new `s` by spaces
                 -1)     //  and keep empty trailing items
  +~- ... .length        //  And append the amount of items minus 1 to the result

Jelly, 7 bytes
ḣḲẈṪ,LƊ

A dyadic Link accepting a list of characters on the left and the 0-indexed index on the right which yields a list of integers, [character, word], again 0-indexed.
Try it online!

I think this should return [4, 4] (10-byte fix).

Thanks @EriktheOutgolfer if we go with 0-indexing it works out nicely for 7.

JavaScript (ES6), 56 bytes
Takes input as (offset)(string).
n=>g=([c,...a],b=i=0)=>n--?g(a,b+!(i+=c!=' '||-i)):[i,b]

Try it online!
Commented
n =>                 // n = desired offset in string
  g = (              // g = recursive function taking:
    [c, ...a],       //   c = current character; a[] = array of remaining characters
    b =              //   b = index of current block
    i = 0            //   i = current position within the current block
  ) =>               //
    n-- ?            // if we haven't reached the desired offset:
      g(             //   do a recursive call to g:
        a,           //     pass the array of remaining characters
        b + !(       //     update b:
          i +=       //       update i:
            c != ' ' //         increment i if the current character is not a space
            || -i    //         or set i to zero if it is
        )            //     increment b if i was set to zero, or leave it unchanged otherwise
      )              //   end of recursive call
    :                // else:
      [i, b]         //   stop recursion and return [i, b]

Bash, 66 bytes
z=$(echo ${i:0:o});echo $z|sed 's/^.* //g'|wc -c;set -- $z;echo $#

1-indexed. $i contains the input, and $o contains the offset
Explanation:
z=$(echo ${LDS:0:o});          # delete the rest of the word
echo $z|sed 's/^.* //g'|wc -c; # remove anything up to the last word, and count what's left.
set -- $z;echo $#              # find the number of words after the stuff after the offset is deleted

Charcoal, 14 bytes
≔⪪…ＳＮ θＩ⟦Ｌ⊟θＬθ

Try it online! Link is to verbose version of code. Explanation:
≔⪪…ＳＮ θ

Truncate the input string to the given length and split on spaces.
Ｉ⟦Ｌ⊟θＬθ

Extract the last string and take its length, then take the number of remaining strings, cast both lengths to string and implicitly print them on separate lines.

Retina 0.8.2, 50 bytes
^.+
$*
^(1)*¶((?<-1>.)*).*
$2
^(.*? )*(.*)
$.2,$#1

Try it online! Takes input in the order offset, string. Explanation:
^.+
$*

Convert the offset to unary.
^(1)*¶((?<-1>.)*).*
$2

Truncate the string to the given length. This uses .NET's balancing groups to count the same number of characters in each string.
^(.*? )*(.*)
$.2,$#1

Count the number of spaces and the number of characters after the last space and output them in decimal in reverse order.

Ruby, 53 48 bytes
->s,n{t=s[0,n];[n-t[/.* |^/].size,t.count(" ")]}

Try it online!


text:
New Order #2: Turn My Way
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the second challenge in this series. The first challenge can be found here.
In this challenge, we use Gray codes to rearrage the natural numbers. A Gray code, or "reflected binary code" is a binary encoding in such a way that two successive values differ in only one bit. A practical application of this encoding is to use it in rotary encoders, hence my reference to "Turn My Way".

Note that this encoding leaves some degree of freedom. For example, following binary 1100, there are four possible following codes: 1101, 1110, 1000 and 0100. This is why I will define \$a(n)\$ as the smallest, not previously used value that differs only one character in binary encoding. This sequence corresponds with A163252.
Since this is a "pure sequence" challenge, the task is to output \$a(n)\$ for a given \$n\$ as input, where \$a(n)\$ is A163252.
Task
Given an integer input \$n\$, output \$a(n)\$ in integer format (not in binary format).
\$a(n)\$ is defined as the least positive integer not occurring earlier in the sequence such that \$a(n-1)\$ and \$a(n)\$ differ in only one bit when written in binary.
Note: 1-based indexing is assumed here; you may use 0-based indexing, so \$a(0) = 1; a(1) = 3\$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
--------------
1     | 1
5     | 4
20    | 18
50    | 48
123   | 121
1234  | 1333
3000  | 3030
9999  | 9997

Rules

Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
Invalid input (0, floats, strings, negative values, etc.) may lead to unpredicted output, errors or (un)defined behaviour. In A163252, \$a(0)\$ is defined as 0. For this challenge, we will ignore this.
Default I/O rules apply.
Default loopholes are forbidden.
This is code-golf, so the shortest answers in bytes wins

Final note
See the following related (but not equal) PP&CG questions:

Finding the next Gray code (input and output in binary)
Generate the all Gray codes of length n

Stax, 19 17 bytes
êÑ{╚α8è╙mc┼σ▀»É▲ü

Run and debug it
It stops working at some point after the specified domain due to the hardcoded bit index iteration. (32767)
Unpacked, ungolfed, and commented, it looks like this.
z0,         push an empty array, literal zero, and the input, in that order
             - the zero represents the last calculated value in the sequence
             - the array contains all the previous ones
D           repeat the rest of the program n times (from input)
  +         append the last calculated value to the array
  17r       [0 .. 16] (these are the bit indices necessary to cover the input range)
  {|2nH|^m  calculate candidate values; previous value with each of these bits toggled
  n-        remove all values previously calculated
  |m        keep the minimum candidate remaining

Run this one

You're 1 byte behind the shortest 05AB1E answer. Do you plan on optimizing this further? Otherwise I'll accept Kevin's answer...

If I have the opportunity I will work on it today, sometime in the next 14 hours.

Allright. I'll keep it open for another day. Good luck!

@agtoever: Thanks.  I'm done now.

Well done! You win! Congratulations!

JavaScript (ES6), 65 bytes
1-indexed.
n=>{for(o=p=[k=1];o[k]|~-(i=p^k)&i?k++:k=o[p=k]=!!n--;);return p}

Try it online!
Commented
n => {                  // n = index of requested term
  for(                  // for loop:
    o =                 //   o = storage object for the terms of the sequence
    p =                 //   p = last term found in the sequence
      [k = 1];          //   k = current term
    o[k] |              //   if k was already encountered
    ~-(i = p ^ k) & i ? //   or (p XOR k) has more than 1 bit set:
      k++               //     increment k
    :                   //   else:
      k = o[p = k]      //     set o[k], set p to k
        = !!n--;        //     stop if n is equal to 0 or set k to 1; decrement n
  );                    // end of for()
  return p              // return p
}                       // end

On TIO, I get a stack overflow for n > ~1024. Any suggestions on how tot deal with that in Abu other environment? Rule: "your program should at least support input and output in theorie range of 1 up tot 32767"

@agtoever I've updated it to a non-recursive version.

Jelly, 26 20 bytes
ṀBLŻ2*^1ị$ḟ⁸Ṃ;
0Ç⁸¡Ḣ

Try it online!
A full program that takes n as the single argument. Works for all test cases. Also note that, although not required, it handles n=0.
Explanation
Helper link: find next term and prepend
Ṁ              | maximum of list so far
 B             | convert to binary
  L            | number of binary digits
   Ż           | 0..above number
    2*         | 2 to the power of each of the above
      ^        | exclusive or with...
       1ị$     | ... the most recent term in the list so far
          ḟ⁸   | filter out anything used already
            Ṃ  | find the minimum
             ; | prepend to existing list

Main link
0              | start with zero
 Ç             | call the above link
  ⁸¡           | and repeat n times
    Ḣ          | take the last term added

Java (JDK), 142 138 124 123 132 130 98 bytes

increased to account for import, saved a byte thanks to @kevin-cruijssen
switched collection to int array thanks to @olivier-grégoire

n->{int s[]=new int[9*n],j,k=0;for(;n-->0;s[k=j]++)for(j=0;s[++j]>0|n.bitCount(j^k)>1;);return k;}

Try it online!

I'm afraid imports has to be included in the byte-count. You can however golf the import java.util.*;+Set s=new HashSet(); to var s=new java.util.HashSet();. In addition, the rest can be golfed to: Integer i=0,j,k=0;for(;i++<n;s.add(k=j))for(j=0;s.contains(++j)|i.bitCount(j^k)>1;);return k;. Nice answer nonetheless, so +1 from me. :)

Thanks! I'm new to this and trying to figure out the obscure rules. :)  And good catch on saving a byte moving the s.add().

Saved 2 more bytes using Stack rather than HashSet. A lot slower but works!

Ah, of course, smart. And no matter how slow, if we can save a byte it's worth it for code-golf challenges. ;p I once had an answer that went from complexity $O(n)$ to $O(n^n)$ by saving a byte, haha xD

s.contains() can be replaced by s.search()>0 saving... 0 bytes.  Dang.

You can still golf it to 126 bytes with the second golf I suggested in my first comment. :)

98 bytes.

@KevinCruijssen Which challenge? You have me quite interested :)

@OlivierGrégoire Not sure anymore.. Might have confused it with the answers here. The comment on my 05AB1E answer states "Code golf - where adding 1 byte to your program to go from n! to n lg n just isn't worth it." And there is also a Jelly answer of 9 bytes with complexity $O(N^2)$ and another of 2 bytes more with complexity $O(N^{0.3})$.

@KevinCruijssen Very nice, thanks for sharing :) I thought Java, but indeed in other languages, 1 byte is often a world of differences ;)

@OlivierGrégoire Oh, haha. I don't think a single byte-change can have that much impact on Java's complexity. :P Unless you change an 9e8 to 9e9 or something like that (although complexity ≠ performance, so the complexity is then still lineair, just with a larger loop). PS: Sorry @Daniel for the chat we have on your answer.. Happens sometimes. ;)

Man, you guys are good at this! Thanks for the tips!

@DanielWiddis You don't update the answer with the golfs?

I do, but I want to understand them first. And that had to wait until my lunch hour.

It's basically your algorithm but backed by an array, plus a few golfs here and there.

@OlivierGrégoire yeah but the n-->0 threw me for a loop (pun intended) until i realized it was n-- > 0.  I tried to observe your improvements and modify my own code as a learning experience.

Python 2, 81 bytes
1-based indexing
l=[0];p=0
exec"n=0\nwhile(p^n)&(p^n)-1or n in l:n+=1\np=n;l+=p,;"*input()
print p

Try it online!

Python 2, 79 bytes
This takes a lot of time (9999 wasn't finished after running locally for 7 minutes)
l={0};p=0;n=input()
exec'p=min({p^2**k for k in range(n)}-l);l|={p};'*n
print p

Try it online!

Maximum input 32767 isn't supported (the default recursion depth isn't system-dependent).

Even the given test case 9999 isn't supported. :)

@EriktheOutgolfer Changed it to an iterative approach, probably still doesn't finish in time on TIO, but runs locally just fine.

@ovs Oh, timeouts alone don't matter.

Cool! I just tried it for n=9999 and it completed successfully after about an hour. +1. Yay! ;-)

Husk, 21 bytes
!¡λḟ¤ȯεΣz≠ȯ↔Θḋ→¹`-N)ø

Try it online! ¡§ḟ¤ȯεΣz≠ȯ↔Θḋ→`-Nø would work if not for type-inferencing issues.

Wolfram Language (Mathematica), 74 bytes
Last@Nest[#~Join~{Min[BitXor[Last@#,2^Range[0,20]]~Complement~#]}&,{0},#]&

Try it online!

APL (Dyalog Extended), 46 bytes
{⍵⌷2∘{(~⍺∊⍵)∧1=≢⍸≠⌿↑⌽∘⊤¨⍺,⊃⌽⍵:⍵,⍺⋄⍵∇⍨⍺+1}⍣⍵⊢1}

Try it online!

Charcoal, 65 bytes
≔⁰θＦＮ«⊞υθ≔¹ηＷ¬‹θ⊗η≦⊗ηＷ∧›η¹∨¬＆θη№υ⁻θη≧÷²ηＷ№υ⁻｜θη＆θη≦⊗η≔⁻｜θη＆θηθ»Ｉθ

Try it online! Link is to verbose version of code. Explanation:
≔⁰θ

Initialise the result to 0.
ＦＮ«

Loop n times.
⊞υθ

Save the previous result so that we don't use it again.
≔¹ηＷ¬‹θ⊗η≦⊗η

Find the highest bit in the previous result.
Ｗ∧›η¹∨¬＆θη№υ⁻θη≧÷²η

While that bit is greater than 1, if the bit is set in the previous result, try subtracting that bit to see if the result is an unseen result. This ensures that the potential results are tried in ascending order of value.
Ｗ№υ⁻｜θη＆θη≦⊗η

Now try XORing that bit with the previous result, doubling the bit until an unseen result is found. This handles the cases when a bit needs to be set, again in ascending order of value, but also the case when the least significant bit needs to be toggled, which the previous loop doesn't bother to test (because it's golfier to test for that here). If the previous loop found an unseen result then this loop never runs; if it didn't then this loop will uselessly retest those results.
≔⁻｜θη＆θηθ

Update the result by actually XORing the bit with it.
»Ｉθ

Output the final result at the end of the loop.

05AB1E, 21 20 18 bytes
ÎFˆ∞.Δ¯θy^bSO¯yå_*

Pretty inefficient, so the larger the input, the longer it takes to get the result. Does work for input 0 as well, though.
Try it online or verify the first \$n\$ terms.
Explanation:
Î                # Push 0 and the input
 F               # Loop the input amount of times:
  ˆ              #  Pop the current number and add it to the global_array
  ∞.Δ            #  Inner loop starting at 1 to find the first number which is truthy for:
     ¯θy^        #   XOR the last number of the global_array with the loop-number `y`
         b       #   Convert it to binary
          SO     #   Sum it's binary digits
     ¯yå_        #   Check if the loop-number `y` is NOT in the global_array yet
            *    #   Multiply both (only if this is 1 (truthy), the inner loop will stop)
                 # (after the loops, output the top of the stack implicitly)

Haskell, 101 bytes
import Data.Bits
(u!n)0=n
(u!n)m|q<-minimum[x|r<-[0..62],x<-[xor(2^r)n],notElem x u]=(n:u)!q$m-1
[]!0

Try it online!
It seems a shame to incur an import just for xor, but I haven't found a good work-around yet. I also wonder if there's a better way to express the loop.

R, 90 bytes
function(n){A=1
while(sum(A|1)<n)A=c(min((x=bitwXor(A[1],2^(0:30)))[x>0&!x%in%A]),A)
A[1]}

Try it online!