Removing 'The' from the start of a string

I have text in my string as follows, e.g.
The Company A
The Company B
Company The C

I would like to remove “The” if it appears at the start. So that the output will be:
Company A
Company B
Company The C

I’m unsure how to use the replace function to achieve this.

2 Likes

Hoi @jon1302,

Please find the below logic.

If left(String1,3).tolower.contains("the")
Then, Assign String1 = String1.substring(2,String1.length-1)

Regards,
Vivek

4 Likes

Hi @jon1302

A simple,solution could be to use Regex expression:

System.Text.RegularExpressions.Regex.Replace(test, “^The”,"") where test is

The Company A
The Company B
Company The C

best regards,
Susana

2 Likes

:stop_sign: For God’s sake… this kind of questions have their answer on Google on the FIRST link… Giving answers in here encourages people not to search anymore… not to study anymore… :stop_sign:

3 Likes

@jon1302

You can find a lot of string operations in the below URLs’. Try on each elements and you can learn deep into String Manipulations

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/keywords/string-manipulation-summary

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/index

1 Like

Hello @Gouda_6,

Please, note that using yourinputString.Replace(“The”,"").Trim you will get

Company A
Company B
Company C

The goal is to replace only the “The” at the start of each line.

Best regards,
Susana

3 Likes

Perfect thank you

1 Like

Very useful, thanks.

1 Like

Hi

Please refer this, this could be a easy solutionsubstring.xaml (5.1 KB)

Thanks.

Hello,

I’m running a process using the below If statement.

Image1

It works fine within one part of the process (Update Invoice Data) but when i use it again in another part of the process it fails (Update Country Data). I receive the following message:
Source: Assign
Message: Index and length must refer to a location within the string.
Parameter name: length
Exception Type: System.ArgumentOutofRangeException

Details:
19.3.0+Branch.master.Sha.5fdb43627d7d3c011018bb545ddf9470210d44a9

Source: Assign

Message: Index and length must refer to a location within the string.
Parameter name: length

Exception Type: System.ArgumentOutOfRangeException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length

  • at System.String.Substring(Int32 startIndex, Int32 length)*
  • at lambda_method(Closure , ActivityContext )*
  • at Microsoft.VisualBasic.Activities.VisualBasicValue`1.Execute(CodeActivityContext context)*
  • at System.Activities.CodeActivity`1.InternalExecuteInResolutionContext(CodeActivityContext context)*
  • at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity`1 expressionActivity)*
  • at System.Activities.InArgument`1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)*
  • at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)*
  • at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary`2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate)*
  • at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex)*
  • at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)*

Any assistance on how to fix would be greatly appreciated.

FAME Validation.xaml (75.9 KB)
CosOver5Employees_UKEir.xlsx (20.5 KB)
Invoice Data.xlsx (676.9 KB)

Didn’t you ask in a different topic how to remove “The” ? Why don’t you continue in the same thread?

@jon1302, use Substring and then assign it to a new string variable.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.