[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: strjust
From: |
Ben Abbott |
Subject: |
Re: strjust |
Date: |
Fri, 15 Oct 2010 06:21:04 -0700 |
On Oct 15, 2010, at 3:39 AM, Jaroslav Hajek <address@hidden> wrote:
> On Fri, Oct 15, 2010 at 9:14 AM, Leo Butler <address@hidden> wrote:
>>
>>
>> On Thu, 14 Oct 2010, Ozzy Lash wrote:
>>
>> < On Thu, Oct 14, 2010 at 4:42 PM, Ben Abbott <address@hidden> wrote:
>> < > On Oct 14, 2010, at 1:58 PM, Ozzy Lash wrote:
>> < >
>> < >> On Thu, Oct 14, 2010 at 3:06 PM, Ben Abbott <address@hidden> wrote:
>> < >>>
>> < >>> On Oct 14, 2010, at 12:20 PM, Ozzy Lash wrote:
>> < >>>
>> < >>>> On Thu, Oct 14, 2010 at 10:36 AM, Ben Abbott <address@hidden> wrote:
>> < >>>>> On Oct 14, 2010, at 7:03 AM, Leo Butler <address@hidden> wrote:
>> < >>>>>
>> < >>>>>> On Wed, 13 Oct 2010, Ben Abbott wrote:
>> < >>>>>>
>> < >>>>>> < On Oct 13, 2010, at 12:16 AM, Leo Butler <address@hidden> wrote:
>> < >>>>>> <
>> < >>>>>> < > In 3.3.52+, I find the following behaviour of strjust,
>> < >>>>>> < > which appears to conflict with its description.
>> < >>>>>> < >
>> < >>>>>> < > octave> s=sprintf("\tstring");
>> < >>>>>> < > octave> s=strjust(s,"left")
>> < >>>>>> < > s = string
>> < >>>>>> < > octave> s=sprintf(" string");
>> < >>>>>> < > octave> s=strjust(s,"left")
>> < >>>>>> < > s = string
>> < >>>>>> < >
>> < >>>>>> < > You can see that it is not removing leading tabs.
>> < >>>>>> < >
>> < >>>>>> < > Leo
>> < >>>>>> <
>> < >>>>>> < Does the description below clarify how strjust functions?
>> < >>>>>> <
>> < >>>>>> < strjust (S)
>> < >>>>>> < strjust (S, "right")
>> < >>>>>> < Returns the text, S, justified to the right.
>> < >>>>>> < strjust (S, "left")
>> < >>>>>> < Returns left justified text.
>> < >>>>>> < strjust (S, "center")
>> < >>>>>> < Returns center justified text.
>> < >>>>>> < Null characters are replaced by spaces.
>> < >>>>>>
>> < >>>>>> Here is the info description:
>> < >>>>>>
>> < >>>>>> -- Function File: strjust (S, ["left"|"right"|"center"])
>> < >>>>>> Shift the non-blank text of S to the left, right or center of
>> the
>> < >>>>>> string. If S is a string array, justify each string in the
>> array.
>> < >>>>>> Null characters are replaced by blanks. If no
>> < >>>>>> justification is
>> < >>>>>> specified, then all rows are right-justified.
>> < >>>>>>
>> < >>>>>> By comparison:
>> < >>>>>> -- Function File: strtrim (S)
>> < >>>>>> Remove leading and trailing blanks and nulls from S.
>> < >>>>>>
>> < >>>>>> And here is how each works:
>> < >>>>>>
>> < >>>>>> octave> s=sprintf("\tstring");
>> < >>>>>> octave> strjust(s,"left")
>> < >>>>>> ans = string
>> < >>>>>> octave> strtrim(s)
>> < >>>>>> ans = string
>> < >>>>>>
>> < >>>>>> You see that the definition of 'blank' is inconsistent.
>> < >>>>>>
>> < >>>>>> Leo
>> < >>>>>
>> < >>>>> I've pushed the change below.
>> < >>>>>
>> < >>>>> http://hg.savannah.gnu.org/hgweb/octave/rev/04c3aacbbc46
>> < >>>>>
>> < >>>>> Thanks
>> < >>>>> Ben
>> < >>>>>
>> < >>>>
>> < >>>> I think I agree with Leo, and that tabs should be treated as
>> < >>>> whitespace (or blanks) and should be stripped for justification, If
>> < >>>> not, I think that there is an issue for right justification as well.
>> < >>>>
>> < >>>
>> < >>> Ok. I hadn't realized Leo was asking that the way strjust() works
>> should be changed.
>> < >>>
>> < >>> How might strjust() be modified and remain compatible with Matlab?
>> < >>>
>> < >>> Ben
>>
>> Ben, thanks for looking into this.
>>
>> To clarify: my original email was a genuine inquiry, not a request
>> for change. However, would it not be possible to modify strjust so that
>> the definition of whitespace can be input by the user, e.g.
>>
>> strjust(string,"left",[9,32])
>> strjust(string,"right",[" ","\t"])
>>
>> The default behaviour need not change.
>>
>> Leo
>>
>
>
> The problem is that tab is very seldom treated as equivalent to a
> single space (or null in this case, which was included for
> compatibility). Usually it's eight or two or whatever. I believe
> that's why it was excluded here. I suggest you use strrep (possibly
> combined with cellstr/strvcat) to replace tabs by whatever amount of
> spaces you consider appropriate, and then use strjust.
>
> hth
Would a tab_to_spaces() be a good idea?
Ben
- Re: strjust, (continued)
- Re: strjust, Ben Abbott, 2010/10/13
- Re: strjust, Leo Butler, 2010/10/14
- Re: strjust, Ben Abbott, 2010/10/14
- Re: strjust, Ozzy Lash, 2010/10/14
- Re: strjust, Ben Abbott, 2010/10/14
- Re: strjust, Ozzy Lash, 2010/10/14
- Re: strjust, Ben Abbott, 2010/10/14
- Re: strjust, Ozzy Lash, 2010/10/14
- Re: strjust, Leo Butler, 2010/10/15
- Re: strjust, Jaroslav Hajek, 2010/10/15
- Re: strjust,
Ben Abbott <=
- Re: strjust, John W. Eaton, 2010/10/15
- Re: strjust, Leo Butler, 2010/10/15
- Re: strjust, Ben Abbott, 2010/10/15
- New function - untabify (was: strjust), Ben Abbott, 2010/10/17
- New function - untabify (was: strjust), John W. Eaton, 2010/10/17
- Re: New function - untabify (was: strjust), Ben Abbott, 2010/10/17
- Re: New function - untabify (was: strjust), John W. Eaton, 2010/10/17
- Re: New function - untabify (was: strjust), John W. Eaton, 2010/10/18
- Re: strjust, Ben Abbott, 2010/10/18
- Re: strjust, Ben Abbott, 2010/10/15