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
Click For Summary

Discussion Overview

The discussion revolves around finding the most efficient method to format and copy a quote in a programming language without using keyboard shortcuts or traditional copy-paste methods. The scope includes programming solutions and scripting approaches.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant suggests that a script could be written in any programming language to append formatting tags to every other letter of a string.
  • Another participant provides a Java implementation that formats a given string by selectively appending characters based on their position.
  • A different participant shares a Python script that achieves similar formatting by alternating the addition of characters to the output string.
  • One participant humorously mentions the challenge of coding in the esoteric language Brainfuck, indicating a playful approach to the topic.

Areas of Agreement / Disagreement

Participants present different programming solutions without reaching a consensus on the most efficient method. Multiple competing views remain regarding the best approach to the problem.

Contextual Notes

Some solutions depend on specific programming languages, and there may be limitations regarding the handling of spaces and formatting tags. The discussion does not resolve the efficiency of the proposed methods.

Dembadon
Gold Member
Messages
660
Reaction score
88
...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?
 
Computer science 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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 44 ·
2
Replies
44
Views
6K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
6K
Replies
17
Views
6K
Replies
10
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
2
Views
3K
  • · Replies 86 ·
3
Replies
86
Views
13K