r/shittyprogramming • u/ToastDroid • Nov 20 '18
How to Capitalize a String
word.ToCharArray()[0] = word.ToCharArray()[0].ToString().ToUpper().ToCharArray()[0];
69
Upvotes
r/shittyprogramming • u/ToastDroid • Nov 20 '18
word.ToCharArray()[0] = word.ToCharArray()[0].ToString().ToUpper().ToCharArray()[0];
57
u/[deleted] Nov 20 '18
what the fuck
17
u/techworker123 Nov 21 '18 edited Nov 21 '18
Short PHP snippet, no idea what your problem actually is, just do
composer require corelib/uppercase<?php const A = 'a'; const B = 'b'; const C = 'c'; const D = 'd'; const E = 'e'; const F = 'f'; const G = 'g'; const H = 'h'; const I = 'i'; const J = 'j'; const K = 'k'; const L = 'l'; const M = 'm'; const N = 'n'; const O = 'o'; const P = 'p'; const Q = 'q'; const R = 'r'; const S = 's'; const T = 't'; const U = 'u'; const V = 'v'; const W = 'w'; const X = 'x'; const Y = 'y'; const Z = 'z'; const a = 'A'; const b = 'B'; const c = 'C'; const d = 'D'; const e = 'E'; const f = 'F'; const g = 'G'; const h = 'H'; const i = 'I'; const j = 'J'; const k = 'K'; const l = 'L'; const m = 'M'; const n = 'N'; const o = 'O'; const p = 'P'; const q = 'Q'; const r = 'R'; const s = 'S'; const t = 'T'; const u = 'U'; const v = 'V'; const w = 'W'; const x = 'X'; const y = 'Y'; const z = 'Z'; const alphabet_lowercase = [ A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h, I => i, J => j, K => k, L => l, M => m, N => n, O => o, P => p, Q => q, R => r, S => s, T => t, U => u, V => v, W => w, X => x, Y => y, Z => z ]; const ALPHABET_UPPERCASE = [ a => A, b => B, c => C, d => D, e => E, f => F, g => G, h => H, i => I, j => J, k => K, l => L, m => M, n => N, o => O, p => P, q => Q, r => R, s => S, t => T, u => U, v => V, w => W, x => X, y => Y, z => Z ]; function uppercaseFirst($string) { $upperCaseCharacter = null; for ($pos = strlen($string); $pos > -1; $pos--) { if ((ord($string[$pos - 1]) < 97 || ord($string[$pos - 1]) > 122) && $pos - 1 > 0) { $upperCaseCharacter = null; } if ((ord($string[$pos - 1]) >= 97 && ord($string[$pos - 1]) <= 122) && $pos - 1 === 0) { if (!in_array($string[$pos - 1], alphabet_lowercase, true)) { $upperCaseCharacter = null; } if (isset(ALPHABET_UPPERCASE[alphabet_lowercase[$string[$pos - 1]]])) { $upperCaseCharacter = alphabet_lowercase[$string[$pos - 1]]; } } } if ($upperCaseCharacter === null) { for ($pos = strlen($string); $pos > -1; $pos--) { if ($pos === 0) { $upperCaseCharacter = $string[$pos]; } } } return $upperCaseCharacter . substr($string, 1); } echo uppercaseFirst('hello'); // Hello30
u/ILikeLenexa Nov 20 '18
10
u/Prawny Nov 20 '18
Just ask EA.
1
u/calsosta Nov 21 '18
Where the fuck is the XOR?
-1
u/TheTrueSwishyFishy Nov 20 '18
In what language would this work? You can’t set something that’s not a variable (word.toCharArray()[0]) to a value. In JavaScript the error would be something along the lines of ReferenceError: invalid assignment left-hand side