473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove any number of spaces before and after slash

7 New Member
Hello everybody
I have data in Column A ..
Inside most of the cells not all I have slash
May be one slash or two or three or four

I need to remove any space before and after the slash ..
Note that the number of spaces are variable ..
Example :
Expand|Select|Wrap|Line Numbers
  1. Hello   /  Everybody            This  is /Just example/  to illustrate /         my task  .
The result should be like the following

Expand|Select|Wrap|Line Numbers
  1. Hello/Everybody            This  is/Just example/to illustrate/my task  .
Note again the spaces before and after the slash only to be removed but other spaces remain as they are

Thanks advanced
May 6 '15 #1
7 3607
Rabbit
12,516 Recognized Expert Moderator MVP
Do you know VBA? You will need to create a custom function to do this. Off the top of my head, Use the Split() function to split it on the slash, Trim() each of the indexes in the resulting array, and then recombine the array into a string.
May 6 '15 #2
YasserKhalil
7 New Member
Thanks Mr. Rabbit for reply
Can you provide me the code or the UDF function that enables me do that task?
May 6 '15 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Sorry, we don't usually write code for people. But if you attempt it yourself and post the code here, we can help troubleshoot it for you.
May 6 '15 #4
YasserKhalil
7 New Member
Ok Mr. Rabbit
Sorry I'm newbie here
Here's a code I tried to modify but I failed
Expand|Select|Wrap|Line Numbers
  1. Sub RemoveSpacesBeforeAfterSlash()
  2.     Dim A, I As Long, M As Object
  3.     With Cells(1).CurrentRegion.Resize(, 1)
  4.         A = .Value
  5.         With CreateObject("VBScript.RegExp")
  6.             .Global = True
  7.             .Pattern = "*( / *)?"
  8.             For I = 1 To UBound(A, 1)
  9.                 If .test(A(I, 1)) Then A(I, 1) = _
  10.                 .Replace(A(I, 1), "/")
  11.             Next
  12.         End With
  13.         .Value = A
  14.     End With
  15. End Sub
  16.  
Regards
May 6 '15 #5
Rabbit
12,516 Recognized Expert Moderator MVP
This doesn't look anything like what I suggested. I don't see the Split function nor the Trim function I mentioned.

And I didn't say anything about using regular expressions. While regular expressions are powerful and can do what you want, they are more complicated to use than my original suggestion.
May 6 '15 #6
Luuk
1,047 Recognized Expert Top Contributor
Indeed, regular expressions are complicated to use.

Use use: .Pattern = "*( / *)?" (Line#7)

It start with a "*", and according to some docs the "*" means:
"Matches the preceding element zero or more times"

So, without looking any further, your regular expression is wrong! ;)
May 7 '15 #7
svh00987
4 New Member
Well... try starting with text to columns and then joining them again...as the no of slashes can vary, you will need to create some logic to loop through.
Nov 2 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4049
by: Danny | last post by:
Given this: "*" the pattern to remove the htnl code between brackets, how can I remove a series of spaces and just make one space. like here is a series of blank...
2
2832
by: BobM | last post by:
I have two strings that I would like to compare. To guarantee the compare is not affected by trailing spaces, I would like to remove them. Will this do: MyTextBox.text.ToString().Trim()?
6
22859
by: Paul | last post by:
Hi just wondering if there is an easy way to remove spaces in a string, tried the trim method but think it is only for leading or trailing spaces. thanks -- Paul G Software engineer.
3
11502
by: VK | last post by:
If it was already answered somewhere, I'll be glad to be pointed to (after the necessary comments on my search abilities :-) I need as booletproof as possible way to strip out whitespaces from...
7
16448
by: Bosconian | last post by:
I know that str.replace(/^\s+|\s+$/g,''); will trim a string of space, but what about removing extra spaces from the middle? Where "hello world"
3
8774
kamill
by: kamill | last post by:
how can i remove blank spaces from text file......is there any function to remove a perticular chr from file...
2
13308
by: hyperlez | last post by:
Hey all I have a column of user membership ids that is 8 characters long. These ids are based on the users surname with number added on the end to uniquely identify each user. My problem is...
1
2494
by: buggtb | last post by:
Hi Guys, I've been given the joyous task of updating some very old scripts at work and I could do with a little help. Our Unix system dumps text files to pseudo spoolers that our windows...
2
2161
by: SwapnilD | last post by:
I'm implementing a feature which reads comma separated txt file from server(one line at a time). Format of file is fixed, There are 3 columns on each row. After reading the row from file I...
2
5102
by: dev saini | last post by:
how to remove number one by one in the calculator text box using JavaScript. its urgent
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.