What is the quickest way to format and copy a quote in a programming language?

  • Thread starter Thread starter Dembadon
  • Start date Start date
  • Tags Tags
    Sleep
AI Thread Summary
The discussion revolves around finding an efficient method to reproduce a specific text formatting without relying on keyboard shortcuts or traditional copy-paste techniques. Users share their experiences and frustrations regarding the time-consuming nature of the task. A participant suggests that scripting in various programming languages could automate the process of adding tags to every other letter in a string. Two code examples are provided: one in Java and another in Python, demonstrating how to achieve the desired output by iterating through each character of the input string and conditionally appending formatting tags. The conversation also touches on the challenge of coding in less common languages, humorously referencing the difficulty of naming one such language.
Dembadon
Gold Member
Messages
658
Reaction score
89
...so forgive the stupid game:

What would be the most efficient way to reproduce the following without using keyboard shortcuts for formatting, or any variant of a quote + copy-paste method?

Do you know how long this took?
 
Physics news on Phys.org
Last edited by a moderator:
[/QUOTE]
Code:
raphael@raphael:~$ cat bored.java
public class bored {
    public static void main(String[] args) {
        String r = "";
        int j = 0;
        for(int i = 0; i < args[0].length(); i++) {
            if (args[0].charAt(i) != ' ' && j++ % 2 == 0) 
                r += String.format("[b][u][i]%s[/b][/u][/i]", args[0].charAt(i));
            else
                r += args[0].charAt(i);
        }
        System.out.println(r);
    }
}
raphael@raphael:~$ javac bored.java
raphael@raphael:~$ java bored "Do you know how long this took?"
[b][u][i]D[/b][/u][/i]o [b][u][i]y[/b][/u][/i]o[b][u][i]u[/b][/u][/i] k[b][u][i]n[/b][/u][/i]o[b][u][i]w[/b][/u][/i] h[b][u][i]o[/b][/u][/i]w [b][u][i]l[/b][/u][/i]o[b][u][i]n[/b][/u][/i]g [b][u][i]t[/b][/u][/i]h[b][u][i]i[/b][/u][/i]s [b][u][i]t[/b][/u][/i]o[b][u][i]o[/b][/u][/i]k[b][u][i]?[/b][/u][/i]
 
Code:
[noparse]borek@invincible ~/python $ cat bored.py
text='Do you know how long this took?'
outtext = ''
switch = 1

for c in text:
   if c == ' ':
      outtext += ' '
   else:
      if switch:
         outtext += '[b][u][i]'+c+'[/i][/u][/b]'
      else:
         outtext += c
      switch = 1 - switch

print outtext
borek@invincible ~/python $ python bored.py
[b][u][i]D[/i][/u][/b]o [b][u][i]y[/i][/u][/b]o[b][u][i]u[/i][/u][/b] k[b][u][i]n[/i][/u][/b]o[b][u][i]w[/i][/u][/b] h[b][u][i]o[/i][/u][/b]w [b][u][i]l[/i][/u][/b]o[b][u][i]n[/i][/u][/b]g [b][u][i]t[/i][/u][/b]h[b][u][i]i[/i][/u][/b]s [b][u][i]t[/i][/u][/b]o[b][u][i]o[/i][/u][/b]k[b][u][i]?[/i][/u][/b][/noparse]

Do you know how long this took?

If you are really bored you should try to code it in brain****

Sigh, one even can't post a proper name of that language.
 
Just ONCE, I wanted to see a post titled Status Update that was not a blatant, annoying spam post by a new member. So here it is. Today was a good day here in Northern Wisconsin. Fall colors are here, no mosquitos, no deer flies, and mild temperature, so my morning run was unusually nice. Only two meetings today, and both went well. The deer that was road killed just down the road two weeks ago is now fully decomposed, so no more smell. Somebody has a spike buck skull for their...
Thread 'RIP George F. Smoot III (1945-2025)'
https://en.wikipedia.org/wiki/George_Smoot https://physics.berkeley.edu/people/faculty/george-smoot-iii https://apc.u-paris.fr/fr/memory-george-fitzgerald-smoot-iii https://elements.lbl.gov/news/honoring-the-legacy-of-george-smoot/ https://www.nobelprize.org/prizes/physics/2006/smoot/facts/ https://www.aps.org/publications/apsnews/200611/nobel.cfm https://inspirehep.net/authors/988263 Structure in the COBE Differential Microwave Radiometer First-Year Maps (Astrophysical Journal...
Back
Top