Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 375 characters in body
Source Link

Python 3, 77 bytes

o=[]
for x in s.split(c): o.append(chr(ord(x[0])-32)+x[1:])
print(''.join(o))
o=[]
for x in s.split(c): o.append(chr(ord(x[0])-32)+x[1:])
print(''.join(o))

Try it online!

This assumes that the string is ASCII encoded and assumes that s and c are preloaded variables containing the input.

for x in s.split(x) #loop through items in the string s split by x
 o.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x
for x in s.split(x) #loop through items in the string s split by x
 o.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

Python 3, 77 bytes

o=[]
for x in s.split(c): o.append(chr(ord(x[0])-32)+x[1:])
print(''.join(o))

This assumes that the string is ASCII encoded.

for x in s.split(x) #loop through items in the string s split by x
 o.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

Python 3, 77 bytes

o=[]
for x in s.split(c): o.append(chr(ord(x[0])-32)+x[1:])
print(''.join(o))

Try it online!

This assumes that the string is ASCII encoded and assumes that s and c are preloaded variables containing the input.

for x in s.split(x) #loop through items in the string s split by x
 o.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

fixed byte size (now includes newlines); edited body
Source Link

Python 3, 7577 bytes

c=[]o=[]
for x in s.split(c): co.append(chr(ord(x[0])-32)+x[1:])
print(''.join(co))

This assumes that the string is ASCII encoded.

for x in s.split(x) #loop through items in the string s split by x
 co.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

Python 3, 75 bytes

c=[]
for x in s.split(c): c.append(chr(ord(x[0])-32)+x[1:])
print(''.join(c))

This assumes that the string is ASCII encoded.

for x in s.split(x) #loop through items in the string s split by x
 c.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

Python 3, 77 bytes

o=[]
for x in s.split(c): o.append(chr(ord(x[0])-32)+x[1:])
print(''.join(o))

This assumes that the string is ASCII encoded.

for x in s.split(x) #loop through items in the string s split by x
 o.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

Source Link

Python 3, 75 bytes

c=[]
for x in s.split(c): c.append(chr(ord(x[0])-32)+x[1:])
print(''.join(c))

This assumes that the string is ASCII encoded.

for x in s.split(x) #loop through items in the string s split by x
 c.append( #add the following to c
 chr( #turn the following number into a character
 ord( #turn the following character into a number
 x[0] #the first character in string x
 )-32 #subtract 32 from this number
 +x[1:] #add everything past and including the second character in string x

This solution works on the fact that in ASCII encoding, lowercase letters are positioned 32 entries after capitalised letters

Edit: i just realised that this also capitalises the first character in the string, which it shouldn't. but i'm quite proud of my nonsense, so i'll leave this up if that's allowed

AltStyle によって変換されたページ (->オリジナル) /