AW: [Oberon] string manipulation

Stauber Sven Philipp sven.stauber at
Tue Jun 22 14:24:23 MEST 2010


> ... learning the *language*; and to talk about it?

Be sure you don't miss the A2 Programming Quickstart Guide ( Also, there is an Oberon & Active Oberon board on our forum ( On you'll find some "Programming in Oberon" books. Last but not least, there is a lot of code around...

> If yes, I have a first question: strings are defined as sequences of characters...

Actually, there are several ways how strings are represented. The simplest one is ARRAY OF CHAR for ASCII strings or UTF-8 encoded strings. In A2, the text system represents characters as LONGINT (Unicode) and strings therefore as ARRAY OF LONGINT.

> ... which will automatically be 0-terminated

No, not automatically. It is implementation specific whether some "string" manipulation functions always result in a new "string" (0X-terminated character sequence) or not.

I suggest that you have a quick look on the following modules:

Strings.Mod (ASCII string manipulation)
KernelLog.Mod (For "debug" output)
Streams.Mod (StringReader & StringWriter, for command output that can be redirected)

Also, for UTF8 and Unicode: Texts.Mod TextUtilities.Mod UTF8Strings.Mod


-----Ursprüngliche Nachricht-----
Von: oberon-bounces at [mailto:oberon-bounces at] Im Auftrag von spir
Gesendet: Dienstag, 22. Juni 2010 12:28
An: oberon
Betreff: [Oberon] string manipulation


I'm an amateur programmer, completely new to Oberon. Is this a proper place to find help in learning the *language*; and to talk about it?

If yes, I have a first question: strings are defined as sequences of characters. But this only seems to define pieces of text in literal notation; there is I guess no corresponding type. If I get it correctly, then we are supposed to store and manipulate strings in ARRAYs OF CHAR, which will automatically be 0-terminated:
"If an expression e of type Te is assigned to a variable v of type Tv, the following happens:
if Tv is ARRAY n OF CHAR and e is a string of length m <n, v[i] becomes ei for i = 0..m -1 and v[m] becomes 0X. "

But this type is a bit unhandy, esp in the fact it cannot be RETURNed.
How are we supposed to deal with strings concretely? For instance, how can I write a procedure text intended to allow outputing a Position:

MODULE aTrial;

	Position = RECORD
		x	: INTEGER;
		y	: INTEGER;

PROCEDURE (VAR pos:Position) text() : ???;
    RETURN ???; (* "x:pos.x,y:pos.y" *)

VAR pos : Position;

    pos.x := 1; pos.y := 2;
    (* write pos.text to stdout *);
END aTrial.

If there is no builtin way to handle strings practically, how can one build a custom tool (a type) for this? I'm aware I could use POINTER TO ARRAY OF CHAR to pass strings around (*), but then I need to explicitely (de)reference all strings.

Another point about strings is the common need to output variable values (for examples, prototyping, testing...). Maybe it's only me beeing blind, but I cannot even find builtin tools to output atomic values... not to evoke arrays or records.


(*) Like in the example Trees module at §11 of the Oberon-2 language report.

vit esse estrany ☣
Oberon at mailing list for ETH Oberon and related systems

More information about the Oberon mailing list