How can I capitalize the first letter of the first word of a list?

How can I capitalize the first letter of the first word of a list?

I would like to capitalize the first letter of the first word of a list.

In this case, the first parameter may or may not be present.

eg Soil description - greyish brown sand vs brown silty sand vs silty sand vs sand, where sand is the primary major conmponent and silty in the secondary major component.

 

Parents
  • There are several ways to create an uppercase first letter in a text string obtained from a field or assembled using a function.  The method used will depend on the source of the text and the desired output.

    If the text string was assembled from a component description function you have 2 options.

    1. You can specify the upper case in the component description table as Pat suggests in his post.  This presumes that the component that you specify as upper case will be the first in the assembled description and that it will always have data.  If the first component does not have data the first component that does have data will not be capitalized as desired.

    2. Fortunately, the component description function itself has a provision for this.  The component description function takes 4 arguments with the last 3 being optional.

    <<ComponentDesc([Component Desc table name],[Uppercase first letter True/False],[End with period True/False],[search text = replacement text])>>

    The first argument is the component description table name

    The second argument is a true/false that if true, capitalizes the first letter of the assembled description.

    The third argument is a true/false that if true, adds a period to the end of the assembled description.

    The fourth argument will do a search and replace in the assembled description.

    Thus to have the first letter of your description capitalized even if the first component does not have data, the component description function in your output template would be something like

    <<ComponentDesc(Tablename,1)>>

    and if you also wanted a period at the end it would be

    <<ComponentDesc(Tablename,1,1)>>

    If the text string is from a field or assembled by other functions, you again have 2 options depending on the desired output.  In the examples below “[TextFunction]” refers to the field or function that creates the text string or list that you want to capitalize.

    1. As Pat stated in his post, you can use the Ucase1st function as in

    <<UCase1st([TextFunction])>>  

    This will force the first character to upper case but it will also force all but the first character to lower case.  Thus “brown silty CLAY, fine.” becomes “Brown silty clay, fine.”

    2. If the above is not the desired effect, I have used the following combination of functions:

    <<UCase(<<Left([TextFunction],1)>>)>><<Mid([TextFunction],2)>>  

    This will keep the original case of everything past the first character but will force the first letter to upper case.  Thus “brown silty CLAY, fine.” becomes “Brown silty CLAY, fine.”  If [TextFunction] is a long complicated formula you can use the Let and Get functions so you do not have to repeat it twice.

  • I tried both of the options above without success. I think I inserted the UCase code in the wrong place. I have pasted my code below. My goal is to get the first letter of each new line to be capitalized. Where should I insert the UCase code? I tried adding the UCase function just before <<Mid(<<Get(Desc)>>,2)>>, but that did not work. Advice?


    <<Let(Color = _
    <<HasData(<<LITHOLOGY.Overide_Color>>,_
    ", <<LITHOLOGY.Overide_Color>>",_
    <<HasData(<<LITHOLOGY.Additional_Color>>,_
    ", <<LITHOLOGY.Color>><<LITHOLOGY.Additional_Color>>",_
    <<HasData(<<LITHOLOGY.Color>>,_
    ", <<LITHOLOGY.Color>>"_
    )>>_
    )>>_
    )>>_
    )>>_
    <<Let(Desc = _
    <<HasData(<<Get(Color)>>,_
    <<Get(Color)>>_
    )>>_
    <<HasData(<<LITHOLOGY.Moisture>>,_
    ", <<LITHOLOGY.Moisture>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Grain Size>>,_
    ", <<LITHOLOGY.Grain Size>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Consistency>>,_
    ", <<LITHOLOGY.Consistency>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Additional_Descriptions>>,_
    ", <<LITHOLOGY.Additional_Descriptions>>"_
    )>>_
    )>>_
    <<Let(LayerDesc = _
    <<HasData(<<LITHOLOGY.Additional_Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>> _
    (<<LITHOLOGY.Geologic_Unit_Symbol>>) / _
    <<LITHOLOGY.Additional_Geologic_Unit>> _
    (<<LITHOLOGY.Addl_Geologic_Unit_Symbol>>)<<B>><<CR>>",_
    <<HasData(<<LITHOLOGY.Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>><<B>><<CR>>"_
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Material_Description>>,_
    "<<LITHOLOGY.Material_Description>>,"_
    )>>_
    <<HasData(<<Get(Desc)>>,_
    <<Mid(<<Get(Desc)>>,2)>>_
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Overide_Description>>,_
    <<LITHOLOGY.Overide_Description>>,_
    <<IIf(<<LITHOLOGY.Comment>>,_
    " - <<LITHOLOGY.Additional_Descriptions>>",_
    <<HasData(<<Get(LayerDesc)>>,_
    <<Get(LayerDesc)>>_
    )>>_
    )>>_
    )>>
Reply
  • I tried both of the options above without success. I think I inserted the UCase code in the wrong place. I have pasted my code below. My goal is to get the first letter of each new line to be capitalized. Where should I insert the UCase code? I tried adding the UCase function just before <<Mid(<<Get(Desc)>>,2)>>, but that did not work. Advice?


    <<Let(Color = _
    <<HasData(<<LITHOLOGY.Overide_Color>>,_
    ", <<LITHOLOGY.Overide_Color>>",_
    <<HasData(<<LITHOLOGY.Additional_Color>>,_
    ", <<LITHOLOGY.Color>><<LITHOLOGY.Additional_Color>>",_
    <<HasData(<<LITHOLOGY.Color>>,_
    ", <<LITHOLOGY.Color>>"_
    )>>_
    )>>_
    )>>_
    )>>_
    <<Let(Desc = _
    <<HasData(<<Get(Color)>>,_
    <<Get(Color)>>_
    )>>_
    <<HasData(<<LITHOLOGY.Moisture>>,_
    ", <<LITHOLOGY.Moisture>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Grain Size>>,_
    ", <<LITHOLOGY.Grain Size>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Consistency>>,_
    ", <<LITHOLOGY.Consistency>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Additional_Descriptions>>,_
    ", <<LITHOLOGY.Additional_Descriptions>>"_
    )>>_
    )>>_
    <<Let(LayerDesc = _
    <<HasData(<<LITHOLOGY.Additional_Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>> _
    (<<LITHOLOGY.Geologic_Unit_Symbol>>) / _
    <<LITHOLOGY.Additional_Geologic_Unit>> _
    (<<LITHOLOGY.Addl_Geologic_Unit_Symbol>>)<<B>><<CR>>",_
    <<HasData(<<LITHOLOGY.Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>><<B>><<CR>>"_
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Material_Description>>,_
    "<<LITHOLOGY.Material_Description>>,"_
    )>>_
    <<HasData(<<Get(Desc)>>,_
    <<Mid(<<Get(Desc)>>,2)>>_
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Overide_Description>>,_
    <<LITHOLOGY.Overide_Description>>,_
    <<IIf(<<LITHOLOGY.Comment>>,_
    " - <<LITHOLOGY.Additional_Descriptions>>",_
    <<HasData(<<Get(LayerDesc)>>,_
    <<Get(LayerDesc)>>_
    )>>_
    )>>_
    )>>
Children
  • It is difficult for me to understand your intent without knowing the types of data in your fields or the intended output.  I am also not clear on what you mean by "My goal is to get the first letter of each new line to be capitalized" as I am not sure what is defined as a new line.  That being said I will try to summarize my understanding of you code and offer a few options to try.  The way I understand the code

    1. Assemble the color description into a variable called "color". this should result in a text string similar to ", black" or ", yellow red"

    2. Assemble a portion of the description into a variable called "desc".  The first component of this is the color assembled above.  This should result in a text string similar to ", yellow red, moist, fine grained, loose"

    3. Assemble the geologic unit description into a variable called "LayerDesc". This should result in bolded text similar to "Allegheny Formation (Pa)/Pottsville Formation(Pp)<<CR>>" or "Pottsville Formation<<CR>>".  Note there is a carriage return after this text that will start a new line for anything following it.  It will also force a vertical space after this text even if nothing follows it.

    At this point nothing has actually been printed yet.

    4. Print the material description followed by a comma.  I am assuming this will be something like "silty sand," or "sandstone,"

    5. Print the contents of the "desc" variable assembled in 2 above.  I am assuming the <<Mid(<<Get(Desc)>>,2)>>_ statement is a remnant from you trying to insert my example uppercase functions here and that what you really meant was <<HasData(<<Get(Desc)>>,<<Get(Desc)>>)>>_.  Also there seems to be an extra right parenthesis in the code here so I am thinking the code pasted was your working copy.  Finally, this seems to double up on commas since the material description has a trailing comma and the desc has a leading comma.

    6. Print the contents of the "LayerDesc" variable assembled above or some type of override description or some type of additional description. For the purposes of this explanation I will assume only the Layer description variable gets printed.

    Thus what finally gets printed is:

    silty sand,, yellow red, moist, fine grained, looseAllegheny Formation (Pa)/Pottsville Formation(Pp)<<CR>>

    My interpretation is that this is what you are considering a "line" thus if you want to capitalize the first character of this line you would place the Ucase function on the material description.  So your code:

    <<HasData(<<LITHOLOGY.Material_Description>>,_
                    "<<LITHOLOGY.Material_Description>>,"_
          )>>_

    Will be modified to(option 1):

    <<HasData(<<LITHOLOGY.Material_Description>>,_
                    "<<Ucase1st(<<LITHOLOGY.Material_Description>>)>>,"_
          )>>_

    Or (option 2):

    <<HasData(<<LITHOLOGY.Material_Description>>,_
                    "<<Ucase(<<Left(<<LITHOLOGY.Material_Description>>,1)>>)>><<Mid(<<LITHOLOGY.Material_Description>>,2)>>,"_
          )>>_

    For the above example either option would print

    Silty sand,, yellow red, moist, fine grained, looseAllegheny Formation (Pa)/Pottsville Formation(Pp)<<CR>>

    This would not work if there was no data in the material description field.  If you want to account for this possibility, I recommend you assemble the final print text string into another variable, say "FinalPrint", using the let function that combines the results of step 4, 5, and 6 above.  Then simply end the code with either:

    <<Ucase1st(<<Get(FinalPrint)>>)>>

    Or

    <<Ucase(<<Left(<<Get(FinalPrint)>>,1)>>)>><<Mid(<<Get(FinalPrint)>>,2)>>

    Note however that both options only look at the first character in the string and makes it upper case if it is a letter.  If the first character is a space, or a comma then a space, nothing will be changed.  There are other text functions that can check for this and deal with it as appropriate but the best way is to avoid the condition. One way to do this is to use the ListBuildSepTrim function

    <<ListBuildSepTrim(<separator>,<<expression 1>>,<<expression 2>>,...)>>

    This allows you to build a string of words separated by a separator, say a comma, that has no leading spaces and no leading comma regardless of which field has data or not.

    Hope this helps.  If I have misinterpreted your intent let me know.

    Note, I have not tested the code I placed above so There may be some typos or other inconsistencies that you will have to work out.

     

  • Szang,

    I have been playing around with the code that you gave me and was able to achieve the desired result to capitalize the first letter of every line; however, I have a hanging comma issue.  Specifically, if there are no additional comments other than a material description, a comma still prints.  

    I have included my edited code below.  I have also attached a preview of my log containing the hanging comma after the material description of gravel.

    <<Let(Color = _
    <<HasData(<<LITHOLOGY.Overide_Color>>,_
    ", <<LITHOLOGY.Overide_Color>>",_
    <<HasData(<<LITHOLOGY.Additional_Color>>,_
    ", <<LITHOLOGY.Color>><<LITHOLOGY.Additional_Color>>",_
    <<HasData(<<LITHOLOGY.Color>>,_
    ", <<LITHOLOGY.Color>>"_
    )>>_
    )>>_
    )>>_
    )>>_
    <<Let(Desc = _
    <<HasData(<<Get(Color)>>,_
    <<Get(Color)>>_
    )>>_
    <<HasData(<<LITHOLOGY.Moisture>>,_
    ", <<LITHOLOGY.Moisture>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Grain Size>>,_
    ", <<LITHOLOGY.Grain Size>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Consistency>>,_
    ", <<LITHOLOGY.Consistency>>"_
    )>>_
    <<HasData(<<LITHOLOGY.Additional_Descriptions>>,_
    ", <<LITHOLOGY.Additional_Descriptions>>"_
    )>>_
    )>>_
    <<Let(LayerDesc = _
    <<HasData(<<LITHOLOGY.Additional_Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>> _
    (<<LITHOLOGY.Geologic_Unit_Symbol>>) / _
    <<LITHOLOGY.Additional_Geologic_Unit>> _
    (<<LITHOLOGY.Addl_Geologic_Unit_Symbol>>)<<B>><<CR>>",_
    <<HasData(<<LITHOLOGY.Geologic_Unit>>,_
    "<<B>><<LITHOLOGY.Geologic_Unit>><<B>><<CR>>"_
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Material_Description>>,_
    "<<LITHOLOGY.Material_Description>>,"_
    )>>_
    <<HasData(<<Get(Desc)>>,_
    <<Mid(<<Get(Desc)>>,2)>>
    )>>_
    )>>_
    <<HasData(<<LITHOLOGY.Overide_Description>>,_
    <<LITHOLOGY.Overide_Description>>,_
    <<IIf(<<LITHOLOGY.Comment>>,_
    " - <<LITHOLOGY.Additional_Descriptions>>",_
    <<HasData(<<Get(LayerDesc)>>,_
    <<Ucase(<<Left(<<Get(LayerDesc)>>,1)>>)>><<Mid(<<Get(LayerDesc)>>,2)>>_
    )>>_
    )>>_
    )>>

  • The preferred way to do this is with the ListBuildSepTrim command I described previously.  This gets rid of all the HasData functions and avoids double commas and leading and trailing commas.

    Working with what you have got, it is best to be consistent and always include the necessary separating punctuation as part of the data that will follow (ie PRECEDING the data).  That way, if there is no data, the separating punctuation does not print.  You started doing this with the "color" and "desc" variables but then abandoned it when you assembled the final description.  In fact you ended up removing the leading coma from the "desc" variable.  I would sugest the following revisions to your final code (identified by bold italics underline).  I did not change your code, only commented on what should be changed

    <<HasData(<<LITHOLOGY.Material_Description>>,_

    "<<LITHOLOGY.Material_Description>>,"_                                Delete the trailing comma from this line

    )>>_

    <<HasData(<<Get(Desc)>>,_

    <<Mid(<<Get(Desc)>>,2)>>                                                  Remove the Mid command from this line to get the leading comma back

    )>>_

    )>>_                                                         It seems like this closing parenthesis is in the wrong place... Needs to be up about 7 lines to close out the "layerdesc" Let statement

    <<HasData(<<LITHOLOGY.Overide_Description>>,_

    <<LITHOLOGY.Overide_Description>>,_                 Add a leading comma to this line

    <<IIf(<<LITHOLOGY.Comment>>,_

    " - <<LITHOLOGY.Additional_Descriptions>>",_   If the dash is the desired separator then this line is fine as is

    <<HasData(<<Get(LayerDesc)>>,_

    <<Ucase(<<Left(<<Get(LayerDesc)>>,1)>>)>><<Mid(<<Get(LayerDesc)>>,2)>>_      If you want a separator here, add it as a leading separator but if there might not be a material description then you will have an extraneous leading separator    

    )>>_

    )>>_

    )>>

    Again, I do not know what type of data you have in your data fields and what the desired result so this may not give you the results you desire.

  • I am having a similar issue trying to capitalize the first word of my string. I believe I applied it based on your recommendation but I am not seeing any changes in the text. My text is listed below:

    <<iif(<<lithology.description>>="No Recovery","No Recovery.","<<hasdata(<<lithology.soil name>>,"<<b>><<u>><<format(<<lithology.soil name>> (<<lithology.graphic>>),>)>><<B>><<u>>
    <<listbuildseptrim(_
    "," ,_
    <<lithology.color>>,_
    <<lithology.moisture_content>>,_
    <<lithology.density_consistency>>,_
    <<lithology.soil_structure>>,_
    <<lithology.mineralogy>>,_
    <<lithology.description>>,_
    )>>","-<<N>><<Ucase1st(<<listbuildseptrim(_
    "," ,_
    <<lithology.color>>,_
    <<lithology.moisture_content>>,_
    <<lithology.density_consistency>>,_
    <<lithology.soil_structure>>,_
    <<lithology.mineralogy>>,_
    <<lithology.description>>,_
    )>>)>><<N>>")>>")>>

  • Hi Domnique,

    As others in this thread have mentioned, the best solution might be the Component Description approach using a Component Description library table and the ComponentDesc function. See Help>Index>Setting up Component Structures - componenent descriptions (how-to guide) for more info. For a detailed explanation, see the Component Lithology Descriptions section in the Data Design Tutorial.

    You could use a long expression such as above, but it might be more difficult to work with. If you would like to use that approach though, please provide more info or an example of what the final completed description should look like in Output, and we can provide better guidance for the best way to write the expression. I see a couple issues with the expression, and I'm not sure what the end goal is exactly.

    Also, feel free to send me your gINT Library File (.glb) and a gINT Project File (.gpj) to jesse.greenwald@bentley.com. It might be easier to troubleshoot that way.

    Thank you,

    Jesse