faqts : Computers : Programming : Languages : Tse : String

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: String: Split: How to split a string in 2 parts at a given position?

Nov 7th, 2006 11:35
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 07 November 2006 - 08:14 pm -------------------

TSE: String: Split: How to split a string in 2 parts at a given 
position?

---

Use e.g. the SubStr() function to take out part of a string.

If you use this function, you will have to supply the given string,
the position where the substring has to start, and finally the
length of that substring.

===

You want thus to split the given string in 2 substrings.

A front string and a tail string.

The front string will start from character 1 of the given string and
end at the given position I. Thus that string will have a length of 1
to I, or thus I.

The tail string will start from the character after the given position
(thus at I + 1) and end at the end of the given string. That substring
will have a length of ( length of the given string, minus its starting
position, plus one). Or thus L - ( I + 1 ) + 1 = L - I, where L is the
total length of the given string.

===

--- cut here: begin --------------------------------------------------

// library: string: change: split (filenamemacro=chanstcs.s) [kn, ho, 
tu, 07-11-2006 20:18:20]

PROC PROCStringChangeSplit( STRING s, INTEGER I )
 IF ( I < 0 )

  Warn( "please choose a value of", " ", I, " ", "greater than zero" )

  RETURN()

 ENDIF

 Warn( SubStr( s, 1, I ) + SubStr( s, I + 1, Length( s ) - I ) )

END

PROC Main()
 INTEGER I = 0
 STRING s[255] = "testing"
 FOR I = 1 TO Length( s )
  Warn( I )
  PROCStringChangeSplit( s, I )
 ENDFOR
END

<F12> Main()

--- cut here: end ----------------------------------------------------

===

This should all the time show the original s, independent
of the value of I (where I between 0 and N (where N > 0)

===

Internet: see also:

---



----------------------------------------------------------------------