Talk:Strip comments from a string: Difference between revisions

m (→‎29 of 36 languages were incorrect?: added whitespace and increased indentation of a table.)
 
(One intermediate revision by one other user not shown)
Line 1:
==General==
Two thoughts. First, wouldn't a comment notation supporting ranges (i.e. /* ... */) as well as truncate tokens ( #, ;, // ...) be more interesting? Otherwise, I'd suggest renaming this task to [[Truncate a String]]. Second (and this is just an idle idea more than anything else), a task for which a language stripped comments (per its own language's rules; // and # for PHP, // and /* */ for C++, etc) would be ''very'' interesting, as it combines demonstrating string processing as well as the language's own comment syntax. --[[User:Short Circuit|Michael Mol]] 13:53, 30 October 2010 (UTC)
:At the very least, the task should define what a comment is. (And, with a nod towards the "comment character inside string" issue, below, what a comment is not...) --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 05:13, 27 July 2022 (UTC)
 
=== Check your data ===
I have done this sort of thing in the past and the problem statement works if the format of what is being parsed does ''not'' allow the comment indicating character to be part of valid data.
 
Line 28 ⟶ 29:
:So far, it seems like comments may contain comment characters, but that the non-comment text cannot quote or escape comment characters. This does not seem very useful. On the other hand, normally comment stripping happens inside of a parser which has mechanics to ignore comment characters when they appear in the wrong context. So the interesting task here is probably [[Parse_EBNF]]. --[[User:Rdm|Rdm]] 17:37, 27 July 2011 (UTC)
::Except [[Parse_EBNF]] task is a little ''too'' elaborate. Here we want a parser based on some BNF, while that task requires ''creating'' a parser based on some BNF, a program writing a program sort of thing. --[[User:Ledrug|Ledrug]] 18:53, 27 July 2011 (UTC)
:::Jump over strings is easy. Get start position of each delimiter and take the lowest one. Test if the count of the string-delimiters on the left side is odd - than the string is open - and search for the closing delimiter. After that point start searching again.--[[User:MichaelWodrich|MichaelWodrich]] ([[User talk:MichaelWodrich|talk]]) 00:01, 29 October 2020 (UTC)
 
== White space ==
6,962

edits